Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,31 @@ where
}
}

/// Used to compare checkpoints
pub trait AsOrd {
/// The type used to compare checkpoint positions
type Ord: Ord + Clone + core::cmp::Ord + crate::lib::std::fmt::Debug;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't Ord + core::cmp::Ord redundant?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, some oversight when combining the commits into one.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Clone and Debug, if this is because LongestMatch impls those traits, wouldn't that be dependent on whether the Ord does so, meaning we don't need these bounds?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove them. Clone was required because I initially stored the ord in LongestMatch. I updated LongestMatch to store the actual checkpoint now.


/// Get comparable value
fn as_ord(&self) -> Self::Ord;
}

impl<'a, T> AsOrd for &'a [T] {
type Ord = *const T;

fn as_ord(&self) -> Self::Ord {
self.as_ptr()
}
}

impl<'a> AsOrd for &'a str {
type Ord = *const u8;

fn as_ord(&self) -> Self::Ord {
self.as_ptr()
}
}

/// Helper trait for types that can be viewed as a byte slice
pub trait AsBytes {
/// Casts the input type to a byte slice
Expand Down Expand Up @@ -2200,6 +2225,22 @@ where
#[derive(Copy, Clone, Debug)]
pub struct Checkpoint<T>(T);

impl<T: PartialEq> PartialEq for Checkpoint<T> {
fn eq(&self, other: &Self) -> bool {
self.0.eq(&other.0)
}
}

impl<T: Eq> Eq for Checkpoint<T> {}
Comment on lines +2228 to +2234
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need these?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are currently used by the tests. We can update the tests to compare the err.into_inner() or compare via format!(...).


impl<T: AsOrd> AsOrd for Checkpoint<T> {
type Ord = T::Ord;

fn as_ord(&self) -> Self::Ord {
self.0.as_ord()
}
}

/// A range bounded inclusively for counting parses performed
#[derive(PartialEq, Eq)]
pub struct Range {
Expand Down