@@ -186,6 +186,13 @@ impl<'de> Deserialize<'de> for Predicate {
186186 de:: Error :: invalid_length ( 2 , & "expected an Ipld value" )
187187 } ) ?,
188188 ) ) ,
189+ "!=" => Ok ( Predicate :: Not ( Box :: new ( Predicate :: Equal (
190+ seq. next_element ( ) ?
191+ . ok_or_else ( || de:: Error :: invalid_length ( 1 , & "expected a selector" ) ) ?,
192+ seq. next_element ( ) ?. ok_or_else ( || {
193+ de:: Error :: invalid_length ( 2 , & "expected an Ipld value" )
194+ } ) ?,
195+ ) ) ) ) ,
189196 ">" => Ok ( Predicate :: GreaterThan (
190197 seq. next_element ( ) ?
191198 . ok_or_else ( || de:: Error :: invalid_length ( 1 , & "expected a selector" ) ) ?,
@@ -249,7 +256,8 @@ impl<'de> Deserialize<'de> for Predicate {
249256 _ => Err ( de:: Error :: unknown_variant (
250257 & op,
251258 & [
252- "==" , ">" , ">=" , "<" , "<=" , "like" , "not" , "and" , "or" , "all" , "any" ,
259+ "==" , "!=" , ">" , ">=" , "<" , "<=" , "like" , "not" , "and" , "or" , "all" ,
260+ "any" ,
253261 ] ,
254262 ) ) ,
255263 }
@@ -1413,4 +1421,36 @@ mod tests {
14131421 Ok ( ( ) )
14141422 }
14151423 }
1424+
1425+ mod roundtrip {
1426+ use super :: * ;
1427+
1428+ #[ test_log:: test]
1429+ fn test_not_equal_dagcbor_roundtrip ( ) -> TestResult {
1430+ let pred = Predicate :: Not ( Box :: new ( Predicate :: Equal (
1431+ Select :: from_str ( ".foo" ) ?,
1432+ Ipld :: Integer ( 42 ) ,
1433+ ) ) ) ;
1434+
1435+ let cbor = serde_ipld_dagcbor:: to_vec ( & pred) ?;
1436+ let back: Predicate = serde_ipld_dagcbor:: from_slice ( & cbor) ?;
1437+
1438+ assert_eq ! ( back, pred) ;
1439+ Ok ( ( ) )
1440+ }
1441+
1442+ #[ test_log:: test]
1443+ fn test_not_equal_ipld_roundtrip ( ) -> TestResult {
1444+ let pred = Predicate :: Not ( Box :: new ( Predicate :: Equal (
1445+ Select :: from_str ( ".bar" ) ?,
1446+ Ipld :: String ( "hello" . into ( ) ) ,
1447+ ) ) ) ;
1448+
1449+ let ipld: Ipld = pred. clone ( ) . into ( ) ;
1450+ let back = Predicate :: try_from ( ipld) ?;
1451+
1452+ assert_eq ! ( back, pred) ;
1453+ Ok ( ( ) )
1454+ }
1455+ }
14161456}
0 commit comments