Skip to content

Commit

Permalink
impl StableDeref for LocatedSpan
Browse files Browse the repository at this point in the history
LocatedSpan is largely just a wrapper around the contained type `T`, so
this marker trait is safe to implement whenever T already implements
StableDeref.
  • Loading branch information
deepinthebuild committed Oct 12, 2020
1 parent 79cf042 commit 2c85930
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ runtime-dispatch-simd = ["bytecount/runtime-dispatch-simd"]
bytecount = "^0.6"
memchr = ">=1.0.1, <3.0.0" # ^1.0.0 + ^2.0
nom = { version = "5.0.0", default-features = false }
stable_deref_trait = "^1"
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ use nom::{
AsBytes, Compare, CompareResult, Err, FindSubstring, FindToken, IResult, InputIter,
InputLength, InputTake, InputTakeAtPosition, Offset, ParseTo, Slice,
};
use stable_deref_trait::StableDeref;

/// A LocatedSpan is a set of meta information about the location of a token, including extra
/// information.
Expand Down Expand Up @@ -146,6 +147,8 @@ impl<T, X> core::ops::Deref for LocatedSpan<T, X> {
}
}

unsafe impl<T: StableDeref, X> StableDeref for LocatedSpan<T, X> {}

impl<T: AsBytes> LocatedSpan<T, ()> {
/// Create a span for a particular input with default `offset` and
/// `line` values and empty extra data.
Expand Down

0 comments on commit 2c85930

Please sign in to comment.