pub struct Replacinator<'a> { /* private fields */ }Implementations§
Source§impl<'a> Replacinator<'a>
impl<'a> Replacinator<'a>
Sourcepub fn new_in<R>(
value: &'a mut str,
with: impl FnMut(&mut Replacinator<'a>) -> R,
) -> R
pub fn new_in<R>( value: &'a mut str, with: impl FnMut(&mut Replacinator<'a>) -> R, ) -> R
pub unsafe fn construct(from: &'a mut str) -> Self
pub fn remainder(&self) -> &str
Sourcepub fn get_begin(&mut self) -> &'a mut str
pub fn get_begin(&mut self) -> &'a mut str
Examples found in repository?
examples/json_parse.rs (line 29)
22fn parse_json_array<'a>(src: &mut Replacinator<'a>) -> JsonArray<'a> {
23 let mut values = Vec::new();
24 assert_eq!(src.skip_char(), Some('['));
25 loop {
26 match src.skip_char() {
27 Some('"') => {
28 // Reset the replacinator to the beginning of this string
29 let _ = src.get_begin();
30 loop {
31 match src
32 .read_char()
33 .expect("JSON value should not end in the middle of a string")
34 {
35 '\\' => match src
36 .read_char()
37 .expect("JSON value should not end in the middle of an escape sequence")
38 {
39 '"' => src.write_char('"'),
40 '\\' => src.write_char('\\'),
41 '/' => src.write_char('/'),
42 'b' => src.write_char('\x08'),
43 'f' => src.write_char('\x0c'),
44 'n' => src.write_char('\n'),
45 'r' => src.write_char('\r'),
46 't' => src.write_char('\t'),
47 'u' => {
48 let mut res = 0;
49 for _ in 0..4 {
50 let v = src
51 .read_char()
52 .expect("String ended in unicode")
53 .to_digit(16)
54 .expect("Invalid hex digit in escape");
55 res = res * 16 + v;
56 }
57 src.write_char(
58 std::char::from_u32(res).expect("Valid character code"),
59 )
60 }
61 other => panic!("Invalid escape {:?}", other),
62 },
63 '"' => {
64 values.push(src.get_begin());
65 src.write_char('"');
66 break;
67 }
68 other => src.write_char(other),
69 }
70 }
71 }
72 Some(']') => break,
73 Some(' ') | Some('\n') | Some('\t') => (),
74 res => panic!(
75 r#"JSON array should be continued with '"' or ']', got {:?}"#,
76 res
77 ),
78 }
79 }
80 JsonArray { values }
81}Sourcepub fn skip_char(&mut self) -> Option<char>
pub fn skip_char(&mut self) -> Option<char>
Examples found in repository?
examples/json_parse.rs (line 24)
22fn parse_json_array<'a>(src: &mut Replacinator<'a>) -> JsonArray<'a> {
23 let mut values = Vec::new();
24 assert_eq!(src.skip_char(), Some('['));
25 loop {
26 match src.skip_char() {
27 Some('"') => {
28 // Reset the replacinator to the beginning of this string
29 let _ = src.get_begin();
30 loop {
31 match src
32 .read_char()
33 .expect("JSON value should not end in the middle of a string")
34 {
35 '\\' => match src
36 .read_char()
37 .expect("JSON value should not end in the middle of an escape sequence")
38 {
39 '"' => src.write_char('"'),
40 '\\' => src.write_char('\\'),
41 '/' => src.write_char('/'),
42 'b' => src.write_char('\x08'),
43 'f' => src.write_char('\x0c'),
44 'n' => src.write_char('\n'),
45 'r' => src.write_char('\r'),
46 't' => src.write_char('\t'),
47 'u' => {
48 let mut res = 0;
49 for _ in 0..4 {
50 let v = src
51 .read_char()
52 .expect("String ended in unicode")
53 .to_digit(16)
54 .expect("Invalid hex digit in escape");
55 res = res * 16 + v;
56 }
57 src.write_char(
58 std::char::from_u32(res).expect("Valid character code"),
59 )
60 }
61 other => panic!("Invalid escape {:?}", other),
62 },
63 '"' => {
64 values.push(src.get_begin());
65 src.write_char('"');
66 break;
67 }
68 other => src.write_char(other),
69 }
70 }
71 }
72 Some(']') => break,
73 Some(' ') | Some('\n') | Some('\t') => (),
74 res => panic!(
75 r#"JSON array should be continued with '"' or ']', got {:?}"#,
76 res
77 ),
78 }
79 }
80 JsonArray { values }
81}pub fn peek(&self) -> Option<char>
Sourcepub fn read_char(&mut self) -> Option<char>
pub fn read_char(&mut self) -> Option<char>
Examples found in repository?
examples/json_parse.rs (line 32)
22fn parse_json_array<'a>(src: &mut Replacinator<'a>) -> JsonArray<'a> {
23 let mut values = Vec::new();
24 assert_eq!(src.skip_char(), Some('['));
25 loop {
26 match src.skip_char() {
27 Some('"') => {
28 // Reset the replacinator to the beginning of this string
29 let _ = src.get_begin();
30 loop {
31 match src
32 .read_char()
33 .expect("JSON value should not end in the middle of a string")
34 {
35 '\\' => match src
36 .read_char()
37 .expect("JSON value should not end in the middle of an escape sequence")
38 {
39 '"' => src.write_char('"'),
40 '\\' => src.write_char('\\'),
41 '/' => src.write_char('/'),
42 'b' => src.write_char('\x08'),
43 'f' => src.write_char('\x0c'),
44 'n' => src.write_char('\n'),
45 'r' => src.write_char('\r'),
46 't' => src.write_char('\t'),
47 'u' => {
48 let mut res = 0;
49 for _ in 0..4 {
50 let v = src
51 .read_char()
52 .expect("String ended in unicode")
53 .to_digit(16)
54 .expect("Invalid hex digit in escape");
55 res = res * 16 + v;
56 }
57 src.write_char(
58 std::char::from_u32(res).expect("Valid character code"),
59 )
60 }
61 other => panic!("Invalid escape {:?}", other),
62 },
63 '"' => {
64 values.push(src.get_begin());
65 src.write_char('"');
66 break;
67 }
68 other => src.write_char(other),
69 }
70 }
71 }
72 Some(']') => break,
73 Some(' ') | Some('\n') | Some('\t') => (),
74 res => panic!(
75 r#"JSON array should be continued with '"' or ']', got {:?}"#,
76 res
77 ),
78 }
79 }
80 JsonArray { values }
81}Sourcepub fn write_char(&mut self, c: char)
pub fn write_char(&mut self, c: char)
Examples found in repository?
examples/json_parse.rs (line 39)
22fn parse_json_array<'a>(src: &mut Replacinator<'a>) -> JsonArray<'a> {
23 let mut values = Vec::new();
24 assert_eq!(src.skip_char(), Some('['));
25 loop {
26 match src.skip_char() {
27 Some('"') => {
28 // Reset the replacinator to the beginning of this string
29 let _ = src.get_begin();
30 loop {
31 match src
32 .read_char()
33 .expect("JSON value should not end in the middle of a string")
34 {
35 '\\' => match src
36 .read_char()
37 .expect("JSON value should not end in the middle of an escape sequence")
38 {
39 '"' => src.write_char('"'),
40 '\\' => src.write_char('\\'),
41 '/' => src.write_char('/'),
42 'b' => src.write_char('\x08'),
43 'f' => src.write_char('\x0c'),
44 'n' => src.write_char('\n'),
45 'r' => src.write_char('\r'),
46 't' => src.write_char('\t'),
47 'u' => {
48 let mut res = 0;
49 for _ in 0..4 {
50 let v = src
51 .read_char()
52 .expect("String ended in unicode")
53 .to_digit(16)
54 .expect("Invalid hex digit in escape");
55 res = res * 16 + v;
56 }
57 src.write_char(
58 std::char::from_u32(res).expect("Valid character code"),
59 )
60 }
61 other => panic!("Invalid escape {:?}", other),
62 },
63 '"' => {
64 values.push(src.get_begin());
65 src.write_char('"');
66 break;
67 }
68 other => src.write_char(other),
69 }
70 }
71 }
72 Some(']') => break,
73 Some(' ') | Some('\n') | Some('\t') => (),
74 res => panic!(
75 r#"JSON array should be continued with '"' or ']', got {:?}"#,
76 res
77 ),
78 }
79 }
80 JsonArray { values }
81}pub fn synchronise(&mut self)
pub fn no_mans_land(&mut self) -> &mut [u8]
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Replacinator<'a>
impl<'a> RefUnwindSafe for Replacinator<'a>
impl<'a> !Send for Replacinator<'a>
impl<'a> !Sync for Replacinator<'a>
impl<'a> Unpin for Replacinator<'a>
impl<'a> !UnwindSafe for Replacinator<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more