Skip to content

Commit

Permalink
Merge pull request #167 from rakaly/lifetime
Browse files Browse the repository at this point in the history
The great lifetime elision
  • Loading branch information
nickbabcock authored Jan 16, 2025
2 parents 2f25159 + 224f35d commit b339dc5
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 67 deletions.
72 changes: 36 additions & 36 deletions src/binary/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct BinaryReaderDeserializer<'res, RES, F, R> {
config: BinaryConfig<'res, RES, F>,
}

impl<'res, RES: TokenResolver, E: BinaryFlavor, R: Read> BinaryReaderDeserializer<'res, RES, E, R> {
impl<RES: TokenResolver, E: BinaryFlavor, R: Read> BinaryReaderDeserializer<'_, RES, E, R> {
/// Deserialize into provided type
pub fn deserialize<T>(&mut self) -> Result<T, Error>
where
Expand All @@ -28,8 +28,8 @@ impl<'res, RES: TokenResolver, E: BinaryFlavor, R: Read> BinaryReaderDeserialize
}
}

impl<'a, 'de, 'res: 'de, RES: TokenResolver, F: BinaryFlavor, R: Read> de::Deserializer<'de>
for &'a mut BinaryReaderDeserializer<'res, RES, F, R>
impl<'de, 'res: 'de, RES: TokenResolver, F: BinaryFlavor, R: Read> de::Deserializer<'de>
for &'_ mut BinaryReaderDeserializer<'res, RES, F, R>
{
type Error = Error;

Expand Down Expand Up @@ -82,8 +82,8 @@ impl<'a, 'res, RES: 'a, F, R> BinaryReaderMap<'a, 'res, RES, F, R> {
}
}

impl<'de, 'a, 'res: 'de, RES: TokenResolver, F: BinaryFlavor, R: Read> MapAccess<'de>
for BinaryReaderMap<'a, 'res, RES, F, R>
impl<'de, 'res: 'de, RES: TokenResolver, F: BinaryFlavor, R: Read> MapAccess<'de>
for BinaryReaderMap<'_, 'res, RES, F, R>
{
type Error = Error;

Expand Down Expand Up @@ -133,7 +133,7 @@ struct BinaryReaderTokenDeserializer<'a, 'res, RES: 'a, F, R> {
token: Token<'a>,
}

impl<'a, 'res, RES: TokenResolver, F, R> BinaryReaderTokenDeserializer<'a, 'res, RES, F, R>
impl<'res, RES: TokenResolver, F, R> BinaryReaderTokenDeserializer<'_, 'res, RES, F, R>
where
F: BinaryFlavor,
R: Read,
Expand Down Expand Up @@ -477,14 +477,14 @@ struct BinaryReaderSeq<'a: 'a, 'res, RES: 'a, F, R> {
hit_end: bool,
}

impl<'a, 'de: 'a, 'res: 'de, RES: 'a, F, R> BinaryReaderSeq<'a, 'res, RES, F, R> {
impl<'a, 'res, RES: 'a, F, R> BinaryReaderSeq<'a, 'res, RES, F, R> {
fn new(de: *const &'a mut BinaryReaderDeserializer<'res, RES, F, R>) -> Self {
BinaryReaderSeq { de, hit_end: false }
}
}

impl<'de, 'a, 'res: 'de, RES: TokenResolver, F: BinaryFlavor, R: Read> SeqAccess<'de>
for BinaryReaderSeq<'a, 'res, RES, F, R>
impl<'de, 'res: 'de, RES: TokenResolver, F: BinaryFlavor, R: Read> SeqAccess<'de>
for BinaryReaderSeq<'_, 'res, RES, F, R>
{
type Error = Error;

Expand Down Expand Up @@ -515,8 +515,8 @@ impl<'a, 'res, RES: 'a, F, R> BinaryReaderEnum<'a, 'res, RES, F, R> {
}
}

impl<'de, 'a, 'res: 'de, RES: TokenResolver, F: BinaryFlavor, R: Read> de::EnumAccess<'de>
for BinaryReaderEnum<'a, 'res, RES, F, R>
impl<'de, 'res: 'de, RES: TokenResolver, F: BinaryFlavor, R: Read> de::EnumAccess<'de>
for BinaryReaderEnum<'_, 'res, RES, F, R>
{
type Error = Error;
type Variant = Self;
Expand All @@ -533,8 +533,8 @@ impl<'de, 'a, 'res: 'de, RES: TokenResolver, F: BinaryFlavor, R: Read> de::EnumA
}
}

impl<'de, 'a, 'res: 'de, RES: TokenResolver, F: BinaryFlavor, R> de::VariantAccess<'de>
for BinaryReaderEnum<'a, 'res, RES, F, R>
impl<'de, 'res: 'de, RES: TokenResolver, F: BinaryFlavor, R> de::VariantAccess<'de>
for BinaryReaderEnum<'_, 'res, RES, F, R>
{
type Error = Error;

Expand Down Expand Up @@ -586,7 +586,7 @@ pub struct OndemandBinaryDeserializer<'data, 'res: 'data, RES, F> {
config: BinaryConfig<'res, RES, F>,
}

impl<'de, 'res, RES: TokenResolver, E: BinaryFlavor> OndemandBinaryDeserializer<'de, 'res, RES, E> {
impl<'de, RES: TokenResolver, E: BinaryFlavor> OndemandBinaryDeserializer<'de, '_, RES, E> {
/// Deserialize into provided type
pub fn deserialize<T>(&mut self) -> Result<T, Error>
where
Expand All @@ -596,8 +596,8 @@ impl<'de, 'res, RES: TokenResolver, E: BinaryFlavor> OndemandBinaryDeserializer<
}
}

impl<'a, 'de, 'res, RES: TokenResolver, F: BinaryFlavor> de::Deserializer<'de>
for &'a mut OndemandBinaryDeserializer<'de, 'res, RES, F>
impl<'de, RES: TokenResolver, F: BinaryFlavor> de::Deserializer<'de>
for &'_ mut OndemandBinaryDeserializer<'de, '_, RES, F>
{
type Error = Error;

Expand Down Expand Up @@ -649,8 +649,8 @@ impl<'a, 'de: 'a, 'res: 'de, RES: 'a, F> OndemandMap<'a, 'de, 'res, RES, F> {
}
}

impl<'de, 'a, 'res: 'de, RES: TokenResolver, F: BinaryFlavor> MapAccess<'de>
for OndemandMap<'a, 'de, 'res, RES, F>
impl<'de, 'res: 'de, RES: TokenResolver, F: BinaryFlavor> MapAccess<'de>
for OndemandMap<'_, 'de, 'res, RES, F>
{
type Error = Error;

Expand Down Expand Up @@ -1023,8 +1023,8 @@ impl<'a, 'de: 'a, 'res: 'de, RES: 'a, F> OndemandSeq<'a, 'de, 'res, RES, F> {
}
}

impl<'de, 'a, 'res: 'de, RES: TokenResolver, F: BinaryFlavor> SeqAccess<'de>
for OndemandSeq<'a, 'de, 'res, RES, F>
impl<'de, 'res: 'de, RES: TokenResolver, F: BinaryFlavor> SeqAccess<'de>
for OndemandSeq<'_, 'de, 'res, RES, F>
{
type Error = Error;

Expand Down Expand Up @@ -1057,8 +1057,8 @@ impl<'a, 'de: 'a, 'res: 'de, RES: 'a, F> OndemandEnum<'a, 'de, 'res, RES, F> {
}
}

impl<'de, 'a, 'res: 'de, RES: TokenResolver, F: BinaryFlavor> de::EnumAccess<'de>
for OndemandEnum<'a, 'de, 'res, RES, F>
impl<'de, 'res: 'de, RES: TokenResolver, F: BinaryFlavor> de::EnumAccess<'de>
for OndemandEnum<'_, 'de, 'res, RES, F>
{
type Error = Error;
type Variant = Self;
Expand All @@ -1075,8 +1075,8 @@ impl<'de, 'a, 'res: 'de, RES: TokenResolver, F: BinaryFlavor> de::EnumAccess<'de
}
}

impl<'de, 'a, 'res: 'de, RES: TokenResolver, F: BinaryFlavor> de::VariantAccess<'de>
for OndemandEnum<'a, 'de, 'res, RES, F>
impl<'de, 'res: 'de, RES: TokenResolver, F: BinaryFlavor> de::VariantAccess<'de>
for OndemandEnum<'_, 'de, 'res, RES, F>
{
type Error = Error;

Expand Down Expand Up @@ -1325,7 +1325,7 @@ where
}
}

impl<'b, 'de, 'res, RES: TokenResolver, E: BinaryFlavor> BinaryDeserializer<'b, 'de, 'res, RES, E> {
impl<'de, RES: TokenResolver, E: BinaryFlavor> BinaryDeserializer<'_, 'de, '_, RES, E> {
/// Deserialize into provided type
pub fn deserialize<T>(&self) -> Result<T, Error>
where
Expand Down Expand Up @@ -1356,8 +1356,8 @@ struct BinaryConfig<'res, RES, F> {
flavor: F,
}

impl<'a, 'b, 'de, 'res, RES: TokenResolver, F: BinaryFlavor> de::Deserializer<'de>
for &'a BinaryDeserializer<'b, 'de, 'res, RES, F>
impl<'de, RES: TokenResolver, F: BinaryFlavor> de::Deserializer<'de>
for &'_ BinaryDeserializer<'_, 'de, '_, RES, F>
{
type Error = Error;

Expand Down Expand Up @@ -1430,8 +1430,8 @@ impl<'c, 'a, 'de, 'res: 'de, RES, E> BinaryMap<'c, 'a, 'de, 'res, RES, E> {
}
}

impl<'c, 'de, 'a, 'res: 'de, RES: TokenResolver, F: BinaryFlavor> MapAccess<'de>
for BinaryMap<'c, 'a, 'de, 'res, RES, F>
impl<'de, 'res: 'de, RES: TokenResolver, F: BinaryFlavor> MapAccess<'de>
for BinaryMap<'_, '_, 'de, 'res, RES, F>
{
type Error = Error;

Expand Down Expand Up @@ -1524,8 +1524,8 @@ fn visit_key<'b, 'de: 'b, 'res: 'de, RES: TokenResolver, F: BinaryFlavor, V: Vis
}
}

impl<'b, 'de, 'res: 'de, RES: TokenResolver, E: BinaryFlavor> de::Deserializer<'de>
for KeyDeserializer<'b, 'de, 'res, RES, E>
impl<'de, 'res: 'de, RES: TokenResolver, E: BinaryFlavor> de::Deserializer<'de>
for KeyDeserializer<'_, 'de, 'res, RES, E>
{
type Error = Error;

Expand Down Expand Up @@ -1560,8 +1560,8 @@ struct ValueDeserializer<'c, 'b: 'c, 'de: 'b, 'res: 'de, RES, E> {
tokens: &'c [BinaryToken<'de>],
}

impl<'c, 'b, 'de, 'res: 'de, RES: TokenResolver, E: BinaryFlavor> de::Deserializer<'de>
for ValueDeserializer<'c, 'b, 'de, 'res, RES, E>
impl<'de, 'res: 'de, RES: TokenResolver, E: BinaryFlavor> de::Deserializer<'de>
for ValueDeserializer<'_, '_, 'de, 'res, RES, E>
{
type Error = Error;

Expand Down Expand Up @@ -1710,7 +1710,7 @@ struct EnumAccess<'b, 'de: 'b, 'res: 'de, RES, E> {
idx: usize,
}

impl<'b, 'de, 'tokens, RES, E> de::EnumAccess<'de> for EnumAccess<'b, 'de, 'tokens, RES, E>
impl<'de, RES, E> de::EnumAccess<'de> for EnumAccess<'_, 'de, '_, RES, E>
where
RES: TokenResolver,
E: BinaryFlavor,
Expand Down Expand Up @@ -1787,8 +1787,8 @@ struct BinarySequence<'b, 'de: 'b, 'res: 'de, RES, E> {
end_idx: usize,
}

impl<'b, 'de, 'res: 'de, RES: TokenResolver, E: BinaryFlavor> SeqAccess<'de>
for BinarySequence<'b, 'de, 'res, RES, E>
impl<'de, 'res: 'de, RES: TokenResolver, E: BinaryFlavor> SeqAccess<'de>
for BinarySequence<'_, 'de, 'res, RES, E>
{
type Error = Error;

Expand Down
2 changes: 1 addition & 1 deletion src/binary/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ pub enum Token<'a> {
Id(u16),
}

impl<'a> Token<'a> {
impl Token<'_> {
fn write_u32(mut wtr: impl std::io::Write, num: u32) -> Result<(), std::io::Error> {
wtr.write_all(&LexemeId::U32.0.to_le_bytes())?;
wtr.write_all(&num.to_le_bytes())
Expand Down
2 changes: 1 addition & 1 deletion src/binary/tape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ enum ParseState {
OpenSecond = 128,
}

impl<'a, 'b> ParserState<'a, 'b> {
impl<'a> ParserState<'a, '_> {
fn offset(&self, data: &[u8]) -> usize {
self.original_length - data.len()
}
Expand Down
6 changes: 3 additions & 3 deletions src/common/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ mod datederive {

struct DateVisitor;

impl<'de> Visitor<'de> for DateVisitor {
impl Visitor<'_> for DateVisitor {
type Value = Date;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
Expand Down Expand Up @@ -1213,7 +1213,7 @@ mod datederive {

struct DateHourVisitor;

impl<'de> Visitor<'de> for DateHourVisitor {
impl Visitor<'_> for DateHourVisitor {
type Value = DateHour;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
Expand Down Expand Up @@ -1254,7 +1254,7 @@ mod datederive {

struct UniformDateVisitor;

impl<'de> Visitor<'de> for UniformDateVisitor {
impl Visitor<'_> for UniformDateVisitor {
type Value = UniformDate;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion src/copyless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct VecAllocation<'a, T: 'a> {
index: usize,
}

impl<'a, T> VecAllocation<'a, T> {
impl<T> VecAllocation<'_, T> {
/// Consumes self and writes the given value into the allocation.
// writing is safe because alloc() ensured enough capacity
// and `Allocation` holds a mutable borrow to prevent anyone else
Expand Down
4 changes: 2 additions & 2 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl ColorSequence {
}
}

impl<'de, 'r> de::Deserializer<'de> for &'r mut ColorSequence {
impl<'de> de::Deserializer<'de> for &'_ mut ColorSequence {
type Error = Error;

fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
Expand Down Expand Up @@ -73,7 +73,7 @@ impl InnerColorSequence {
}
}

impl<'de, 'r> de::Deserializer<'de> for &'r mut InnerColorSequence {
impl<'de> de::Deserializer<'de> for &'_ mut InnerColorSequence {
type Error = Error;

fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
Expand Down
4 changes: 2 additions & 2 deletions src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ impl<'a> Scalar<'a> {
}
}

impl<'a> fmt::Debug for Scalar<'a> {
impl fmt::Debug for Scalar<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Scalar {{ {} }}", self)
}
}

impl<'a> fmt::Display for Scalar<'a> {
impl fmt::Display for Scalar<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.is_ascii() {
write!(f, "{}", decode_windows1252(self.data))
Expand Down
Loading

0 comments on commit b339dc5

Please sign in to comment.