Skip to content

Commit

Permalink
revert some unrelated changes
Browse files Browse the repository at this point in the history
  • Loading branch information
asmello committed Oct 14, 2024
1 parent 0553cef commit c5e561b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ impl Pointer {
///
/// ## Examples
/// ```
/// let mut ptr = jsonptr::PointerBuf::root();
/// let mut ptr = jsonptr::PointerBuf::new();
/// assert!(ptr.is_empty());
///
/// ptr.push_back("foo");
Expand Down Expand Up @@ -861,10 +861,8 @@ impl PointerBuf {
///
/// ## Errors
/// Returns a [`ParseError`] if the string is not a valid JSON Pointer.
pub fn parse(s: impl Into<String>) -> Result<Self, ParseError> {
let s = s.into();
validate(&s)?;
Ok(Self(s))
pub fn parse<S: AsRef<str> + ?Sized>(s: &S) -> Result<Self, ParseError> {
Pointer::parse(&s).map(Pointer::to_buf)
}

/// Creates a new `PointerBuf` from a slice of non-encoded strings.
Expand Down Expand Up @@ -1509,15 +1507,15 @@ mod tests {
assert_eq!(ptr, Pointer::root());
}
{
let mut ptr = PointerBuf::root();
let mut ptr = PointerBuf::new();
assert_eq!(ptr.tokens().count(), 0);
ptr.push_back("");
assert_eq!(ptr.tokens().count(), 1);
ptr.pop_back();
assert_eq!(ptr.tokens().count(), 0);
}
{
let mut ptr = PointerBuf::root();
let mut ptr = PointerBuf::new();
let input = ["", "", "", "foo", "", "bar", "baz", ""];
for (idx, &s) in input.iter().enumerate() {
assert_eq!(ptr.tokens().count(), idx);
Expand Down Expand Up @@ -1711,7 +1709,7 @@ mod tests {
#[test]
fn pop_back_works_with_empty_strings() {
{
let mut ptr = PointerBuf::root();
let mut ptr = PointerBuf::new();
ptr.push_back("");
ptr.push_back("");
ptr.push_back("bar");
Expand All @@ -1723,18 +1721,18 @@ mod tests {
assert_eq!(ptr.tokens().count(), 1);
ptr.pop_back();
assert_eq!(ptr.tokens().count(), 0);
assert_eq!(ptr, PointerBuf::root());
assert_eq!(ptr, PointerBuf::new());
}
{
let mut ptr = PointerBuf::root();
let mut ptr = PointerBuf::new();
assert_eq!(ptr.tokens().count(), 0);
ptr.push_back("");
assert_eq!(ptr.tokens().count(), 1);
ptr.pop_back();
assert_eq!(ptr.tokens().count(), 0);
}
{
let mut ptr = PointerBuf::root();
let mut ptr = PointerBuf::new();
let input = ["", "", "", "foo", "", "bar", "baz", ""];
for (idx, &s) in input.iter().enumerate() {
assert_eq!(ptr.tokens().count(), idx);
Expand Down
3 changes: 3 additions & 0 deletions src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ impl<'a> Token<'a> {
///
/// This is like [`Self::from_encoded`], except that no validation is
/// performed on the input string.
///
/// ## Safety
/// Input string must be RFC 6901 encoded.
pub(crate) unsafe fn from_encoded_unchecked(inner: impl Into<Cow<'a, str>>) -> Self {
Self {
inner: inner.into(),
Expand Down

0 comments on commit c5e561b

Please sign in to comment.