Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "imstr"
version = "0.2.0"
edition = "2021"
version = "0.3.0"
edition = "2024"
description = "Cheaply clonable and slicable immutable strings"
documentation = "https://docs.rs/imstr"
repository = "https://github.com/xfbs/imstr"
Expand All @@ -21,9 +21,9 @@ name = "peg-list"
required-features = ["peg"]

[dependencies]
nom = { version = "7.1.3", optional = true }
peg-runtime = { version = "0.8.1", optional = true }
serde = { version = "1.0.159", features = ["derive"], optional = true }
nom = { version = "8", optional = true }
peg-runtime = { version = "0.8", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }

[features]
default = []
Expand All @@ -37,3 +37,4 @@ std = []
[dev-dependencies]
criterion = "0.4.0"
peg = "0.8.1"
nom-language = "0.1.0"
27 changes: 17 additions & 10 deletions examples/nom-json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ use nom::{
bytes::complete::{escaped, tag, take_while},
character::complete::{alphanumeric1 as alphanumeric, char, one_of},
combinator::{cut, map, opt, value},
error::{context, convert_error, ContextError, ParseError, VerboseError},
error::{context, ContextError, ParseError},
multi::separated_list0,
number::complete::double,
sequence::{delimited, preceded, separated_pair, terminated},
Err, IResult,
Err, IResult, Parser,
};
use nom_language::error::{convert_error, VerboseError};
use std::collections::HashMap;

#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -77,7 +78,7 @@ fn test_string_inner() {
fn boolean<E: ParseError<ImString>>(input: ImString) -> IResult<ImString, bool, E> {
let parse_true = value(true, tag("true"));
let parse_false = value(false, tag("false"));
alt((parse_true, parse_false))(input)
alt((parse_true, parse_false)).parse(input)
}

#[test]
Expand All @@ -90,7 +91,7 @@ fn test_boolean() {
}

fn null<E: ParseError<ImString>>(input: ImString) -> IResult<ImString, (), E> {
value((), tag("null"))(input)
value((), tag("null")).parse(input)
}

#[test]
Expand All @@ -108,7 +109,8 @@ fn string<E: ParseError<ImString> + ContextError<ImString>>(
context(
"string",
preceded(char('\"'), cut(terminated(string_inner, char('\"')))),
)(i)
)
.parse(i)
}

fn array<E: ParseError<ImString> + ContextError<ImString>>(
Expand All @@ -123,7 +125,8 @@ fn array<E: ParseError<ImString> + ContextError<ImString>>(
preceded(sp, char(']')),
)),
),
)(i)
)
.parse(i)
}

fn key_value<E: ParseError<ImString> + ContextError<ImString>>(
Expand All @@ -133,7 +136,8 @@ fn key_value<E: ParseError<ImString> + ContextError<ImString>>(
preceded(sp, string),
cut(preceded(sp, char(':'))),
json_value,
)(i)
)
.parse(i)
}

fn hash<E: ParseError<ImString> + ContextError<ImString>>(
Expand All @@ -151,7 +155,8 @@ fn hash<E: ParseError<ImString> + ContextError<ImString>>(
preceded(sp, char('}')),
)),
),
)(i)
)
.parse(i)
}

fn json_value<E: ParseError<ImString> + ContextError<ImString>>(
Expand All @@ -167,7 +172,8 @@ fn json_value<E: ParseError<ImString> + ContextError<ImString>>(
map(boolean, JsonValue::Boolean),
map(null, |_| JsonValue::Null),
)),
)(i)
)
.parse(i)
}

fn root<E: ParseError<ImString> + ContextError<ImString>>(
Expand All @@ -181,7 +187,8 @@ fn root<E: ParseError<ImString> + ContextError<ImString>>(
map(null, |_| JsonValue::Null),
)),
opt(sp),
)(i)
)
.parse(i)
}

fn main() {
Expand Down
12 changes: 6 additions & 6 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ impl<T> Data<T> for Arc<T> {
}

fn get(&self) -> &T {
&self
self
}

fn get_mut(&mut self) -> Option<&mut T> {
Arc::get_mut(self)
}

fn ptr_eq(&self, other: &Self) -> bool {
Arc::ptr_eq(&self, &other)
Arc::ptr_eq(self, other)
}
}

Expand All @@ -133,15 +133,15 @@ impl<T> Data<T> for Rc<T> {
}

fn get(&self) -> &T {
&self
self
}

fn get_mut(&mut self) -> Option<&mut T> {
Rc::get_mut(self)
}

fn ptr_eq(&self, other: &Self) -> bool {
Rc::ptr_eq(&self, &other)
Rc::ptr_eq(self, other)
}
}

Expand All @@ -151,15 +151,15 @@ impl<T: Clone> Data<T> for Box<T> {
}

fn get(&self) -> &T {
&self
self
}

fn get_mut(&mut self) -> Option<&mut T> {
Some(self)
}

fn ptr_eq(&self, other: &Self) -> bool {
core::ptr::eq(&self, &other)
core::ptr::eq(self, other)
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Error types
use alloc::fmt::{Display, Formatter, Result};
pub use alloc::string::{FromUtf16Error, FromUtf8Error};
pub use alloc::string::{FromUtf8Error, FromUtf16Error};

/// A possible error when slicing a [`ImString`](crate::ImString).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down Expand Up @@ -46,8 +46,8 @@ fn slice_error_traits() {
// implements partial eq
assert_eq!(error, new);
// implements debug
alloc::format!("{error:?}");
let _ = alloc::format!("{error:?}");
// implements display
alloc::format!("{new}");
let _ = alloc::format!("{new}");
}
}
Loading