-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
226 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use crate::{Pointer, Token, Tokens}; | ||
|
||
pub enum Component<'t> { | ||
Check warning on line 3 in src/component.rs
|
||
/// The document root | ||
Root, | ||
/// A segment of a JSON Pointer | ||
Token(Token<'t>), | ||
} | ||
impl<'t> From<Token<'t>> for Component<'t> { | ||
fn from(token: Token<'t>) -> Self { | ||
Self::Token(token) | ||
} | ||
} | ||
|
||
pub struct Components<'t> { | ||
Check warning on line 15 in src/component.rs
|
||
tokens: Tokens<'t>, | ||
} | ||
impl<'t> Components<'t> { | ||
pub(crate) fn new(tokens: Tokens<'t>) -> Self { | ||
Self { tokens } | ||
} | ||
} | ||
|
||
impl<'t> Iterator for Components<'t> { | ||
type Item = Component<'t>; | ||
fn next(&mut self) -> Option<Self::Item> { | ||
if !self.tokens.has_sent { | ||
self.tokens.has_sent = true; | ||
return Some(Component::Root); | ||
} | ||
self.tokens.next().map(Component::Token) | ||
} | ||
} | ||
|
||
impl<'t> From<&'t Pointer> for Components<'t> { | ||
fn from(pointer: &'t Pointer) -> Self { | ||
Self { | ||
tokens: pointer.tokens(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.