@@ -379,16 +379,17 @@ pub(crate) struct NetworkFilterListV0DeserializeFmt {
379
379
pub unique_domains_hashes_map : HashMap < crate :: utils:: Hash , u16 > ,
380
380
}
381
381
382
- impl From < NetworkFilterListV0DeserializeFmt > for NetworkFilterList {
383
- fn from ( v : NetworkFilterListV0DeserializeFmt ) -> Self {
384
- let _ = fb:: root_as_network_filter_list ( & v. flatbuffer_memory )
385
- . expect ( "Flatbuffer is not corrupted" ) ;
386
- Self {
382
+ impl TryFrom < NetworkFilterListV0DeserializeFmt > for NetworkFilterList {
383
+ fn try_from ( v : NetworkFilterListV0DeserializeFmt ) -> Result < Self , Self :: Error > {
384
+ let _ = fb:: root_as_network_filter_list ( & v. flatbuffer_memory ) ?;
385
+ Ok ( Self {
387
386
flatbuffer_memory : v. flatbuffer_memory ,
388
387
filter_map : v. filter_map ,
389
388
unique_domains_hashes_map : v. unique_domains_hashes_map ,
390
- }
389
+ } )
391
390
}
391
+
392
+ type Error = DeserializationError ;
392
393
}
393
394
394
395
/// Structural representation of adblock engine data that can be built up from deserialization and
@@ -471,25 +472,25 @@ impl<'a> From<(&'a Blocker, &'a CosmeticFilterCache)> for SerializeFormat<'a> {
471
472
}
472
473
}
473
474
474
- impl From < DeserializeFormat > for ( Blocker , CosmeticFilterCache ) {
475
- fn from ( v : DeserializeFormat ) -> Self {
475
+ impl TryFrom < DeserializeFormat > for ( Blocker , CosmeticFilterCache ) {
476
+ fn try_from ( v : DeserializeFormat ) -> Result < Self , Self :: Error > {
476
477
use crate :: cosmetic_filter_cache:: HostnameFilterBin ;
477
478
478
479
let mut specific_rules: HostnameRuleDb = v. specific_rules . into ( ) ;
479
480
specific_rules. procedural_action = HostnameFilterBin ( v. procedural_action ) ;
480
481
specific_rules. procedural_action_exception =
481
482
HostnameFilterBin ( v. procedural_action_exception ) ;
482
483
483
- (
484
+ Ok ( (
484
485
Blocker {
485
- csp : v. csp . into ( ) ,
486
- exceptions : v. exceptions . into ( ) ,
487
- importants : v. importants . into ( ) ,
488
- redirects : v. redirects . into ( ) ,
486
+ csp : v. csp . try_into ( ) ? ,
487
+ exceptions : v. exceptions . try_into ( ) ? ,
488
+ importants : v. importants . try_into ( ) ? ,
489
+ redirects : v. redirects . try_into ( ) ? ,
489
490
removeparam : NetworkFilterList :: default ( ) ,
490
- filters_tagged : v. filters_tagged . into ( ) ,
491
- filters : v. filters . into ( ) ,
492
- generic_hide : v. generic_hide . into ( ) ,
491
+ filters_tagged : v. filters_tagged . try_into ( ) ? ,
492
+ filters : v. filters . try_into ( ) ? ,
493
+ generic_hide : v. generic_hide . try_into ( ) ? ,
493
494
494
495
tags_enabled : Default :: default ( ) ,
495
496
tagged_filters_all : v. tagged_filters_all . into_iter ( ) . map ( |f| f. into ( ) ) . collect ( ) ,
@@ -507,6 +508,8 @@ impl From<DeserializeFormat> for (Blocker, CosmeticFilterCache) {
507
508
508
509
misc_generic_selectors : v. misc_generic_selectors ,
509
510
} ,
510
- )
511
+ ) )
511
512
}
513
+
514
+ type Error = DeserializationError ;
512
515
}
0 commit comments