File tree 2 files changed +30
-16
lines changed
2 files changed +30
-16
lines changed Original file line number Diff line number Diff line change @@ -779,6 +779,10 @@ impl CharwiseDoubleArrayAhoCorasick {
779
779
///
780
780
/// * `source` - A source slice.
781
781
///
782
+ /// # Returns
783
+ ///
784
+ /// A tuple of the automaton and the slice not used for the deserialization.
785
+ ///
782
786
/// # Safety
783
787
///
784
788
/// The given data must be a correct automaton exported by
@@ -794,7 +798,7 @@ impl CharwiseDoubleArrayAhoCorasick {
794
798
/// let pma = CharwiseDoubleArrayAhoCorasick::new(patterns).unwrap();
795
799
/// let bytes = pma.serialize_to_vec();
796
800
///
797
- /// let pma = unsafe {
801
+ /// let ( pma, _) = unsafe {
798
802
/// CharwiseDoubleArrayAhoCorasick::deserialize_from_slice_unchecked(&bytes)
799
803
/// };
800
804
///
@@ -811,7 +815,7 @@ impl CharwiseDoubleArrayAhoCorasick {
811
815
///
812
816
/// assert_eq!(None, it.next());
813
817
/// ```
814
- pub unsafe fn deserialize_from_slice_unchecked ( mut source : & [ u8 ] ) -> Self {
818
+ pub unsafe fn deserialize_from_slice_unchecked ( mut source : & [ u8 ] ) -> ( Self , & [ u8 ] ) {
815
819
let states_len = u32:: from_le_bytes ( source[ 0 ..4 ] . try_into ( ) . unwrap ( ) ) as usize ;
816
820
source = & source[ 4 ..] ;
817
821
let mut states = Vec :: with_capacity ( states_len) ;
@@ -831,12 +835,15 @@ impl CharwiseDoubleArrayAhoCorasick {
831
835
let num_states_array: [ u8 ; 4 ] = source[ 1 ..5 ] . try_into ( ) . unwrap ( ) ;
832
836
let num_states = u32:: from_le_bytes ( num_states_array) as usize ;
833
837
834
- Self {
835
- states,
836
- outputs,
837
- match_kind,
838
- num_states,
839
- }
838
+ (
839
+ Self {
840
+ states,
841
+ outputs,
842
+ match_kind,
843
+ num_states,
844
+ } ,
845
+ & source[ 5 ..] ,
846
+ )
840
847
}
841
848
842
849
/// # Safety
Original file line number Diff line number Diff line change @@ -1066,6 +1066,10 @@ impl DoubleArrayAhoCorasick {
1066
1066
///
1067
1067
/// * `source` - A source slice.
1068
1068
///
1069
+ /// # Returns
1070
+ ///
1071
+ /// A tuple of the automaton and the slice not used for the deserialization.
1072
+ ///
1069
1073
/// # Safety
1070
1074
///
1071
1075
/// The given data must be a correct automaton exported by
@@ -1081,7 +1085,7 @@ impl DoubleArrayAhoCorasick {
1081
1085
/// let pma = DoubleArrayAhoCorasick::new(patterns).unwrap();
1082
1086
/// let bytes = pma.serialize_to_vec();
1083
1087
///
1084
- /// let pma = unsafe {
1088
+ /// let ( pma, _) = unsafe {
1085
1089
/// DoubleArrayAhoCorasick::deserialize_from_slice_unchecked(&bytes)
1086
1090
/// };
1087
1091
///
@@ -1098,7 +1102,7 @@ impl DoubleArrayAhoCorasick {
1098
1102
///
1099
1103
/// assert_eq!(None, it.next());
1100
1104
/// ```
1101
- pub unsafe fn deserialize_from_slice_unchecked ( mut source : & [ u8 ] ) -> Self {
1105
+ pub unsafe fn deserialize_from_slice_unchecked ( mut source : & [ u8 ] ) -> ( Self , & [ u8 ] ) {
1102
1106
let states_len = u32:: from_le_bytes ( source[ 0 ..4 ] . try_into ( ) . unwrap ( ) ) as usize ;
1103
1107
source = & source[ 4 ..] ;
1104
1108
let mut states = Vec :: with_capacity ( states_len) ;
@@ -1118,12 +1122,15 @@ impl DoubleArrayAhoCorasick {
1118
1122
let num_states_array: [ u8 ; 4 ] = source[ 1 ..5 ] . try_into ( ) . unwrap ( ) ;
1119
1123
let num_states = u32:: from_le_bytes ( num_states_array) as usize ;
1120
1124
1121
- Self {
1122
- states,
1123
- outputs,
1124
- match_kind,
1125
- num_states,
1126
- }
1125
+ (
1126
+ Self {
1127
+ states,
1128
+ outputs,
1129
+ match_kind,
1130
+ num_states,
1131
+ } ,
1132
+ & source[ 5 ..] ,
1133
+ )
1127
1134
}
1128
1135
1129
1136
/// # Safety
You can’t perform that action at this time.
0 commit comments