Struct janetrs::JanetString

source ·
pub struct JanetString<'data> { /* private fields */ }
Expand description

Janet strings are a immutable type that are similar to Janet buffers.

§Example

You can easily create a Janet string from Rust str and bytes slice with new:

use janetrs::JanetString;

let jstr = JanetString::new("Hello, World");
let jstr2 = JanetString::new(b"Janet! A bottle of water please!");

You can also use the builder API to create a in a more dynamic way

use janetrs::JanetString;

let size = 13;
let jstr = JanetString::builder(size)
    .put("H")
    .put("ello, ")
    .put(b"World!")
    .finalize();

Implementations§

source§

impl<'data> JanetString<'data>

source

pub fn new(buffer: impl AsRef<[u8]>) -> Self

Create a JanetString from a given buffer.

§Examples
use janetrs::JanetString;

let s = JanetString::new("Hey there!");
source

pub const unsafe fn from_raw(raw: *const u8) -> Self

Create a new JanetString with a raw pointer.

§Safety

This function do not check if the given raw is NULL or not. Use at your own risk.

source

pub fn builder(len: i32) -> JanetStringBuilder<'data>

Created a builder for creating the JanetString.

If the given len is lesser than zero it behaves the same as if len is zero.

source

pub fn len(&self) -> i32

Returns the length of this JanetString, in bytes, not chars or graphemes. In other words, it may not be what a human considers the length of the string.

§Examples
use janetrs::JanetString;

let s = JanetString::new("Hey there!");
assert_eq!(s.len(), 10);
source

pub fn is_empty(&self) -> bool

Returns true if this JanetString has a length of zero, and false otherwise.

§Examples
use janetrs::JanetString;

let s = JanetString::new("Hey there!");
assert!(!s.is_empty());

let s = JanetString::new("");
assert!(s.is_empty());
source

pub fn as_bytes(&self) -> &[u8]

Returns a byte slice of the JanetString contents.

§Examples
use janetrs::JanetString;

let s = JanetString::new("hello");

assert_eq!(&[104, 101, 108, 108, 111], s.as_bytes());
source

pub fn contains(&self, needle: impl AsRef<[u8]>) -> bool

Returns true if and only if this string contains the given needle.

§Examples
use janetrs::JanetString;

let s = JanetString::new("Hey there");

assert!(s.contains("the"))
source

pub fn starts_with(&self, prefix: impl AsRef<[u8]>) -> bool

Returns true if and only if this string has the given prefix.

§Examples
use janetrs::JanetString;

assert!(JanetString::new("foo bar").starts_with("foo"));
assert!(!JanetString::new("foo bar").starts_with("bar"));
assert!(!JanetString::new("foo bar").starts_with("foobar"));
source

pub fn ends_with(&self, suffix: impl AsRef<[u8]>) -> bool

Returns true if and only if this string has the given suffix.

§Examples
use janetrs::JanetString;

assert!(!JanetString::new("foo bar").ends_with("foo"));
assert!(JanetString::new("foo bar").ends_with("bar"));
assert!(!JanetString::new("foo bar").ends_with("foobar"));
source

pub fn is_ascii(&self) -> bool

Returns true if and only if every byte in this string is ASCII.

ASCII is an encoding that defines 128 codepoints. A byte corresponds to an ASCII codepoint if and only if it is in the inclusive range [0, 127].

§Examples
use janetrs::JanetString;

assert!(JanetString::new("abc").is_ascii());
assert!(!JanetString::new("☃βツ").is_ascii());
source

pub fn is_utf8(&self) -> bool

Returns true if and only if the entire string is valid UTF-8.

If you need location information about where a string’s first invalid UTF-8 byte is, then use the to_str method.

§Examples
use janetrs::JanetString;

assert!(JanetString::new("abc").is_utf8());
assert!(JanetString::new("☃βツ").is_utf8());
// invalid bytes
assert!(!JanetString::new(&b"abc\xFF"[..]).is_utf8());
// surrogate encoding
assert!(!JanetString::new(&b"\xED\xA0\x80"[..]).is_utf8());
// incomplete sequence
assert!(!JanetString::new(&b"\xF0\x9D\x9Ca"[..]).is_utf8());
// overlong sequence
assert!(!JanetString::new(&b"\xF0\x82\x82\xAC"[..]).is_utf8());
source

pub fn to_lowercase(&self) -> Self

Available on crate feature unicode only.

Returns a new JanetString containing the lowercase equivalent of this string.

In this case, lowercase is defined according to the Lowercase Unicode property.

If invalid UTF-8 is seen, or if a character has no lowercase variant, then it is written to the given buffer unchanged.

Note that some characters in this string may expand into multiple characters when changing the case, so the number of bytes written to the given string may not be equivalent to the number of bytes in this string.

If you’d like to reuse an allocation for performance reasons, then use to_lowercase_into instead.

§Examples

Basic usage:

use janetrs::JanetString;

let s = JanetString::new("HELLO Β");
assert_eq!(s.to_lowercase(), JanetString::new("hello β"));

Scripts without case are not changed:

use janetrs::JanetString;

let s = JanetString::new("农历新年");
assert_eq!(s.to_lowercase(), JanetString::new("农历新年"));

Invalid UTF-8 remains as is:

use janetrs::JanetString;

let s = JanetString::new(&b"FOO\xFFBAR\xE2\x98BAZ"[..]);
assert_eq!(
    s.to_lowercase(),
    JanetString::new(&b"foo\xFFbar\xE2\x98baz"[..])
);
source

pub fn to_lowercase_into(&self, buf: &mut JanetBuffer<'_>)

Available on crate feature unicode only.

Writes the lowercase equivalent of this string into the given buffer. The buffer is not cleared before written to.

In this case, lowercase is defined according to the Lowercase Unicode property.

If invalid UTF-8 is seen, or if a character has no lowercase variant, then it is written to the given buffer unchanged.

Note that some characters in this string may expand into multiple characters when changing the case, so the number of bytes written to the given buffer may not be equivalent to the number of bytes in this string.

If you don’t need to amortize allocation and instead prefer convenience, then use to_lowercase instead.

§Examples

Basic usage:

use janetrs::{JanetBuffer, JanetString};

let s = JanetString::new("HELLO Β");

let mut buf = JanetBuffer::new();
s.to_lowercase_into(&mut buf);
assert_eq!("hello β".as_bytes(), buf.as_bytes());

Scripts without case are not changed:

use janetrs::{JanetBuffer, JanetString};

let s = JanetString::new("农历新年");

let mut buf = JanetBuffer::new();
s.to_lowercase_into(&mut buf);
assert_eq!("农历新年".as_bytes(), buf.as_bytes());

Invalid UTF-8 remains as is:

use janetrs::{JanetBuffer, JanetString};

let s = JanetString::new(&b"FOO\xFFBAR\xE2\x98BAZ"[..]);

let mut buf = JanetBuffer::new();
s.to_lowercase_into(&mut buf);
assert_eq!(
    JanetBuffer::from(&b"foo\xFFbar\xE2\x98baz"[..]).as_bytes(),
    buf.as_bytes()
);
source

pub fn to_ascii_lowercase(&self) -> Self

Returns a new JanetBuffer containing the ASCII lowercase equivalent of this buffer.

In this case, lowercase is only defined in ASCII letters. Namely, the letters A-Z are converted to a-z. All other bytes remain unchanged. In particular, the length of the buffer returned is always equivalent to the length of this buffer.

§Examples

Basic usage:

use janetrs::JanetString;

let s = JanetString::new("HELLO Β");
assert_eq!(s.to_ascii_lowercase(), JanetString::new("hello Β"));

Invalid UTF-8 remains as is:

use janetrs::JanetString;

let s = JanetString::new(&b"FOO\xFFBAR\xE2\x98BAZ"[..]);
assert_eq!(
    s.to_ascii_lowercase(),
    JanetString::new(&b"foo\xFFbar\xE2\x98baz"[..])
);
source

pub fn to_uppercase(&self) -> Self

Available on crate feature unicode only.

Returns a new JanetString containing the uppercase equivalent of this string.

In this case, uppercase is defined according to the Uppercase Unicode property.

If invalid UTF-8 is seen, or if a character has no uppercase variant, then it is written to the given buffer unchanged.

Note that some characters in this string may expand into multiple characters when changing the case, so the number of bytes written to the given buffer may not be equivalent to the number of bytes in this string.

If you’d like to reuse an allocation for performance reasons, then use to_uppercase_into instead.

§Examples

Basic usage:

use janetrs::JanetString;

let s = JanetString::new("hello β");
assert_eq!(s.to_uppercase(), JanetString::new("HELLO Β"));

Scripts without case are not changed:

use janetrs::JanetString;

let s = JanetString::new("农历新年");
assert_eq!(s.to_uppercase(), JanetString::new("农历新年"));

Invalid UTF-8 remains as is:

use janetrs::JanetString;

let s = JanetString::new(&b"foo\xFFbar\xE2\x98baz"[..]);
assert_eq!(
    s.to_uppercase(),
    JanetString::new(&b"FOO\xFFBAR\xE2\x98BAZ"[..])
);
source

pub fn to_uppercase_into(&self, buf: &mut JanetBuffer<'_>)

Available on crate feature unicode only.

Writes the uppercase equivalent of this string into the given buffer. The buffer is not cleared before written to.

In this case, uppercase is defined according to the Uppercase Unicode property.

If invalid UTF-8 is seen, or if a character has no uppercase variant, then it is written to the given buffer unchanged.

Note that some characters in this buffer may expand into multiple characters when changing the case, so the number of bytes written to the given buffer may not be equivalent to the number of bytes in this buffer.

If you don’t need to amortize allocation and instead prefer convenience, then use to_uppercase instead.

§Examples

Basic usage:

use janetrs::{JanetBuffer, JanetString};

let s = JanetString::new("hello β");

let mut buf = JanetBuffer::new();
s.to_uppercase_into(&mut buf);
assert_eq!(buf.as_bytes(), "HELLO Β".as_bytes());

Scripts without case are not changed:

use janetrs::{JanetBuffer, JanetString};

let s = JanetString::new("农历新年");

let mut buf = JanetBuffer::new();
s.to_uppercase_into(&mut buf);
assert_eq!(buf.as_bytes(), "农历新年".as_bytes());

Invalid UTF-8 remains as is:

use janetrs::{JanetBuffer, JanetString};

let s = JanetString::new(&b"foo\xFFbar\xE2\x98baz"[..]);

let mut buf = JanetBuffer::new();
s.to_uppercase_into(&mut buf);
assert_eq!(buf.as_bytes(), &b"FOO\xFFBAR\xE2\x98BAZ"[..]);
source

pub fn to_ascii_uppercase(&self) -> Self

Returns a new JanetString containing the ASCII uppercase equivalent of this string.

In this case, uppercase is only defined in ASCII letters. Namely, the letters a-z are converted to A-Z. All other bytes remain unchanged. In particular, the length of the string returned is always equivalent to the length of this string.

§Examples

Basic usage:

use janetrs::JanetString;

let s = JanetString::new("hello β");
assert_eq!(s.to_ascii_uppercase().as_bytes(), "HELLO β".as_bytes());

Invalid UTF-8 remains as is:

use janetrs::JanetString;

let s = JanetString::new(&b"foo\xFFbar\xE2\x98baz"[..]);
assert_eq!(
    s.to_ascii_uppercase().as_bytes(),
    &b"FOO\xFFBAR\xE2\x98BAZ"[..]
);
source

pub fn trim(&self) -> Self

Available on crate feature unicode only.

Return a string with leading and trailing whitespace removed.

Whitespace is defined according to the terms of the White_Space Unicode property.

§Examples

Basic usage:

use janetrs::JanetString;

let s = JanetString::new(" foo\tbar\t\u{2003}\n");
assert_eq!(s.trim(), JanetString::new("foo\tbar"));
source

pub fn trim_start(&self) -> Self

Available on crate feature unicode only.

Return a string with leading whitespace removed.

Whitespace is defined according to the terms of the White_Space Unicode property.

§Examples

Basic usage:

use janetrs::JanetString;

let s = JanetString::new(" foo\tbar\t\u{2003}\n");
assert_eq!(s.trim_start(), JanetString::new("foo\tbar\t\u{2003}\n"));
source

pub fn trim_end(&self) -> Self

Available on crate feature unicode only.

Return a string with trailing whitespace removed.

Whitespace is defined according to the terms of the White_Space Unicode property.

§Examples

Basic usage:

use janetrs::JanetString;

let s = JanetString::new(" foo\tbar\t\u{2003}\n");
assert_eq!(s.trim_end(), JanetString::new(" foo\tbar"));
source

pub fn trim_with<F: FnMut(char) -> bool>(&self, trim: F) -> Self

Return a string with leading and trailing characters satisfying the given predicate removed.

§Examples

Basic usage:

use janetrs::JanetString;

let s = JanetString::new("123foo5bar789");
assert_eq!(s.trim_with(|c| c.is_numeric()), JanetString::new("foo5bar"),);
source

pub fn trim_start_with<F: FnMut(char) -> bool>(&self, trim: F) -> Self

Return a string with leading characters satisfying the given predicate removed.

§Examples

Basic usage:

use janetrs::JanetString;

let s = JanetString::new("123foo5bar789");
assert_eq!(
    s.trim_start_with(|c| c.is_numeric()),
    JanetString::new("foo5bar789")
);
source

pub fn trim_end_with<F: FnMut(char) -> bool>(&self, trim: F) -> Self

Return a string with trailing characters satisfying the given predicate removed.

§Examples

Basic usage:

use janetrs::JanetString;

let s = JanetString::new("123foo5bar");
assert_eq!(
    s.trim_end_with(|c| c.is_numeric()),
    JanetString::new("123foo5bar")
);
source

pub fn to_str(&self) -> Result<&str, Utf8Error>

Safely convert this string into a &str if it’s valid UTF-8.

If this string is not valid UTF-8, then an error is returned. The error returned indicates the first invalid byte found and the length of the error.

In cases where a lossy conversion to &str is acceptable, then use one of the to_str_lossy or to_str_lossy_into methods.

source

pub unsafe fn to_str_unchecked(&self) -> &str

Unsafely convert this string into a &str, without checking for valid UTF-8.

§Safety

Callers must ensure that this string is valid UTF-8 before calling this method. Converting a string into a &str that is not valid UTF-8 is considered undefined behavior.

This routine is useful in performance sensitive contexts where the UTF-8 validity of the string is already known and it is undesirable to pay the cost of an additional UTF-8 validation check that to_str performs.

source

pub fn to_str_lossy(&self) -> Cow<'_, str>

Convert this string to a valid UTF-8 string by replacing invalid UTF-8 bytes with the Unicode replacement codepoint (U+FFFD).

If the string is already valid UTF-8, then no copying or allocation is performed and a borrowed string slice is returned. If the string is not valid UTF-8, then an owned string string is returned with invalid bytes replaced by the replacement codepoint.

This method uses the “substitution of maximal subparts” (Unicode Standard, Chapter 3, Section 9) strategy for inserting the replacement codepoint. Specifically, a replacement codepoint is inserted whenever a byte is found that cannot possibly lead to a valid code unit sequence. If there were previous bytes that represented a prefix of a well-formed code unit sequence, then all of those bytes are substituted with a single replacement codepoint. The “substitution of maximal subparts” strategy is the same strategy used by W3C’s Encoding standard. For a more precise description of the maximal subpart strategy, see the Unicode Standard, Chapter 3, Section 9. See also Public Review Issue #121.

N.B. Rust’s standard library also appears to use the same strategy, but it does not appear to be an API guarantee.

source

pub fn to_str_lossy_into(&self, dest: &mut String)

Copy the contents of this string into the given owned string string, while replacing invalid UTF-8 code unit sequences with the Unicode replacement codepoint (U+FFFD).

This method uses the same “substitution of maximal subparts” strategy for inserting the replacement codepoint as the to_str_lossy method.

This routine is useful for amortizing allocation. However, unlike to_str_lossy, this routine will always copy the contents of this string into the destination string, even if this string is valid UTF-8.

source

pub fn to_os_str(&self) -> Result<&OsStr, Utf8Error>

Available on crate feature std only.

Create an OS string slice from this string.

On Unix, this always succeeds and is zero cost. On non-Unix systems, this returns a UTF-8 decoding error if this string is not valid UTF-8. (For example, on Windows, file paths are allowed to be a sequence of arbitrary 16-bit integers. There is no obvious mapping from an arbitrary sequence of 8-bit integers to an arbitrary sequence of 16-bit integers.)

source

pub fn to_os_str_lossy(&self) -> Cow<'_, OsStr>

Available on crate feature std only.

Lossily create an OS string slice from this string.

On Unix, this always succeeds and is zero cost. On non-Unix systems, this will perform a UTF-8 check and lossily convert this string into valid UTF-8 using the Unicode replacement codepoint.

Note that this can prevent the correct round-tripping of file paths on non-Unix systems such as Windows, where file paths are an arbitrary sequence of 16-bit integers.

source

pub fn to_path(&self) -> Result<&Path, Utf8Error>

Available on crate feature std only.

Create a path slice from this string.

On Unix, this always succeeds and is zero cost. On non-Unix systems, this returns a UTF-8 decoding error if this string is not valid UTF-8. (For example, on Windows, file paths are allowed to be a sequence of arbitrary 16-bit integers. There is no obvious mapping from an arbitrary sequence of 8-bit integers to an arbitrary sequence of 16-bit integers.)

source

pub fn to_path_lossy(&self) -> Cow<'_, Path>

Available on crate feature std only.

Lossily create a path slice from this string.

On Unix, this always succeeds and is zero cost. On non-Unix systems, this will perform a UTF-8 check and lossily convert this string into valid UTF-8 using the Unicode replacement codepoint.

Note that this can prevent the correct round-tripping of file paths on non-Unix systems such as Windows, where file paths are an arbitrary sequence of 16-bit integers.

source

pub fn find(&self, needle: impl AsRef<[u8]>) -> Option<usize>

Returns the index of the first occurrence of the given needle.

The needle may be any type that can be cheaply converted into a &[u8]. This includes, but is not limited to, &str and &[u8].

§Complexity

This routine is guaranteed to have worst case linear time complexity with respect to both the needle and the haystack. That is, this runs in O(needle.len() + haystack.len()) time.

This routine is also guaranteed to have worst case constant space complexity.

§Examples
use janetrs::JanetString;

let s = JanetString::new("foo bar baz");
assert_eq!(Some(0), s.find("foo"));
assert_eq!(Some(4), s.find("bar"));
assert_eq!(None, s.find("quux"));
source

pub fn rfind(&self, needle: impl AsRef<[u8]>) -> Option<usize>

Returns the index of the last occurrence of the given needle.

The needle may be any type that can be cheaply converted into a &[u8]. This includes, but is not limited to, &str and &[u8].

§Complexity

This routine is guaranteed to have worst case linear time complexity with respect to both the needle and the haystack. That is, this runs in O(needle.len() + haystack.len()) time.

This routine is also guaranteed to have worst case constant space complexity.

§Examples
use janetrs::JanetString;

let s = JanetString::new("foo bar baz");
assert_eq!(Some(0), s.rfind("foo"));
assert_eq!(Some(4), s.rfind("bar"));
assert_eq!(Some(8), s.rfind("ba"));
assert_eq!(None, s.rfind("quux"));
source

pub fn find_byte(&self, byte: u8) -> Option<usize>

Returns the index of the first occurrence of the given byte. If the byte does not occur in this string, then None is returned.

§Examples
use janetrs::JanetString;

assert_eq!(Some(10), JanetString::new("foo bar baz").find_byte(b'z'));
assert_eq!(None, JanetString::new("foo bar baz").find_byte(b'y'));
source

pub fn rfind_byte(&self, byte: u8) -> Option<usize>

Returns the index of the last occurrence of the given byte. If the byte does not occur in this string, then None is returned.

§Examples
use janetrs::JanetString;

assert_eq!(Some(10), JanetString::new("foo bar baz").rfind_byte(b'z'));
assert_eq!(None, JanetString::new("foo bar baz").rfind_byte(b'y'));
source

pub fn find_char(&self, ch: char) -> Option<usize>

Returns the index of the first occurrence of the given codepoint. If the codepoint does not occur in this string, then None is returned.

Note that if one searches for the replacement codepoint, \u{FFFD}, then only explicit occurrences of that encoding will be found. Invalid UTF-8 sequences will not be matched.

§Examples
use janetrs::JanetString;

assert_eq!(Some(10), JanetString::new("foo bar baz").find_char('z'));
assert_eq!(Some(4), JanetString::new("αβγγδ").find_char('γ'));
assert_eq!(None, JanetString::new("foo bar baz").find_char('y'));
source

pub fn rfind_char(&self, ch: char) -> Option<usize>

Returns the index of the last occurrence of the given codepoint. If the codepoint does not occur in this string, then None is returned.

Note that if one searches for the replacement codepoint, \u{FFFD}, then only explicit occurrences of that encoding will be found. Invalid UTF-8 sequences will not be matched.

§Examples
use janetrs::JanetString;

assert_eq!(Some(10), JanetString::new("foo bar baz").rfind_char('z'));
assert_eq!(Some(6), JanetString::new("αβγγδ").rfind_char('γ'));
assert_eq!(None, JanetString::new("foo bar baz").rfind_char('y'));
source

pub fn find_byteset(&self, byteset: impl AsRef<[u8]>) -> Option<usize>

Returns the index of the first occurrence of any of the bytes in the provided set.

The byteset may be any type that can be cheaply converted into a &[u8]. This includes, but is not limited to, &str and &[u8], but note that passing a &str which contains multibyte characters may not behave as you expect: each byte in the &str is treated as an individual member of the byte set.

Note that order is irrelevant for the byteset parameter, and duplicate bytes present in its body are ignored.

§Complexity

This routine is guaranteed to have worst case linear time complexity with respect to both the set of bytes and the haystack. That is, this runs in O(byteset.len() + haystack.len()) time.

This routine is also guaranteed to have worst case constant space complexity.

§Examples
use janetrs::JanetString;

assert_eq!(JanetString::new("foo bar baz").find_byteset(b"zr"), Some(6));
assert_eq!(
    JanetString::new("foo baz bar").find_byteset(b"bzr"),
    Some(4)
);
assert_eq!(None, JanetString::new("foo baz bar").find_byteset(b"\t\n"));
source

pub fn find_not_byteset(&self, byteset: impl AsRef<[u8]>) -> Option<usize>

Returns the index of the first occurrence of a byte that is not a member of the provided set.

The byteset may be any type that can be cheaply converted into a &[u8]. This includes, but is not limited to, &str and &[u8], but note that passing a &str which contains multibyte characters may not behave as you expect: each byte in the &str is treated as an individual member of the byte set.

Note that order is irrelevant for the byteset parameter, and duplicate bytes present in its body are ignored.

§Complexity

This routine is guaranteed to have worst case linear time complexity with respect to both the set of bytes and the haystack. That is, this runs in O(byteset.len() + haystack.len()) time.

This routine is also guaranteed to have worst case constant space complexity.

§Examples
use janetrs::JanetString;

assert_eq!(
    JanetString::new("foo bar baz").find_not_byteset(b"fo "),
    Some(4)
);
assert_eq!(
    JanetString::new("\t\tbaz bar").find_not_byteset(b" \t\r\n"),
    Some(2)
);
assert_eq!(
    JanetString::new("foo\nbaz\tbar").find_not_byteset(b"\t\n"),
    Some(0)
);
source

pub fn rfind_byteset(&self, byteset: impl AsRef<[u8]>) -> Option<usize>

Returns the index of the last occurrence of any of the bytes in the provided set.

The byteset may be any type that can be cheaply converted into a &[u8]. This includes, but is not limited to, &str and &[u8], but note that passing a &str which contains multibyte characters may not behave as you expect: each byte in the &str is treated as an individual member of the byte set.

Note that order is irrelevant for the byteset parameter, and duplicate bytes present in its body are ignored.

§Complexity

This routine is guaranteed to have worst case linear time complexity with respect to both the set of bytes and the haystack. That is, this runs in O(byteset.len() + haystack.len()) time.

This routine is also guaranteed to have worst case constant space complexity.

§Examples
use janetrs::JanetString;

assert_eq!(
    JanetString::new("foo bar baz").rfind_byteset(b"agb"),
    Some(9)
);
assert_eq!(
    JanetString::new("foo baz bar").rfind_byteset(b"rabz "),
    Some(10)
);
assert_eq!(
    JanetString::new("foo baz bar").rfind_byteset(b"\n123"),
    None
);
source

pub fn rfind_not_byteset(&self, byteset: impl AsRef<[u8]>) -> Option<usize>

Returns the index of the last occurrence of a byte that is not a member of the provided set.

The byteset may be any type that can be cheaply converted into a &[u8]. This includes, but is not limited to, &str and &[u8], but note that passing a &str which contains multibyte characters may not behave as you expect: each byte in the &str is treated as an individual member of the byte set.

Note that order is irrelevant for the byteset parameter, and duplicate bytes present in its body are ignored.

§Complexity

This routine is guaranteed to have worst case linear time complexity with respect to both the set of bytes and the haystack. That is, this runs in O(byteset.len() + haystack.len()) time.

This routine is also guaranteed to have worst case constant space complexity.

§Examples
use janetrs::JanetString;

assert_eq!(
    JanetString::new("foo bar baz,\t").rfind_not_byteset(b",\t"),
    Some(10)
);
assert_eq!(
    JanetString::new("foo baz bar").rfind_not_byteset(b"rabz "),
    Some(2)
);
assert_eq!(
    None,
    JanetString::new("foo baz bar").rfind_not_byteset(b"barfoz ")
);
source

pub fn find_iter<'a, 'b, B>(&'a self, needle: &'b B) -> Find<'a, 'b>
where B: ?Sized + AsRef<[u8]>,

Creates an iterator of the non-overlapping occurrences of the given needle. The iterator yields byte offset positions indicating the start of each match.

§Complexity

This routine is guaranteed to have worst case linear time complexity with respect to both the needle and the haystack. That is, this runs in O(needle.len() + haystack.len()) time.

This routine is also guaranteed to have worst case constant space complexity.

§Examples

Basic usage:

use janetrs::JanetString;

let s = JanetString::new("foo bar foo foo quux foo");
let matches: Vec<usize> = s.find_iter("foo").collect();
assert_eq!(matches, vec![0, 8, 12, 21]);

An empty string matches at every position, including the position immediately following the last byte:

use janetrs::JanetString;

let matches: Vec<usize> = JanetString::new("foo").find_iter("").collect();
assert_eq!(matches, vec![0, 1, 2, 3]);

let matches: Vec<usize> = JanetString::new("").find_iter("").collect();
assert_eq!(matches, vec![0]);
source

pub fn rfind_iter<'a, 'b, B>(&'a self, needle: &'b B) -> FindReverse<'a, 'b>
where B: ?Sized + AsRef<[u8]>,

Creates an iterator of the non-overlapping occurrences of the given needle in reverse. The iterator yields byte offset positions indicating the start of each match.

§Complexity

This routine is guaranteed to have worst case linear time complexity with respect to both the needle and the haystack. That is, this runs in O(needle.len() + haystack.len()) time.

This routine is also guaranteed to have worst case constant space complexity.

§Examples

Basic usage:

use janetrs::JanetString;

let s = JanetString::new("foo bar foo foo quux foo");
let matches: Vec<usize> = s.rfind_iter("foo").collect();
assert_eq!(matches, vec![21, 12, 8, 0]);

An empty string matches at every position, including the position immediately following the last byte:

use janetrs::JanetString;

let matches: Vec<usize> = JanetString::new("foo").rfind_iter("").collect();
assert_eq!(matches, vec![3, 2, 1, 0]);

let matches: Vec<usize> = JanetString::new("").rfind_iter("").collect();
assert_eq!(matches, vec![0]);
source

pub fn bytes(&self) -> Bytes<'_>

Creates an iterator over the bytes of the JanetString.

§Examples
use janetrs::JanetString;

let s = JanetString::new("Hello");

assert_eq!(s.bytes().collect::<Vec<u8>>(), b"Hello");
source

pub fn chars(&self) -> Chars<'_>

Creates an iterator over the Unicode scalar values in this string. If invalid UTF-8 is encountered, then the Unicode replacement codepoint is yielded instead.

§Examples
use janetrs::JanetString;

let s = JanetString::new(b"\xE2\x98\x83\xFF\xF0\x9D\x9E\x83\xE2\x98\x61");

let chars: Vec<char> = s.chars().collect();
assert_eq!(vec!['☃', '\u{FFFD}', '𝞃', '\u{FFFD}', 'a'], chars);
source

pub fn char_indices(&self) -> CharIndices<'_>

Creates an iterator over the Unicode scalar values in this janet string along with their starting and ending byte index positions. If invalid UTF-8 is encountered, then the Unicode replacement codepoint is yielded instead.

Note that this is slightly different from the CharIndices iterator provided by the standard library. Aside from working on possibly invalid UTF-8, this iterator provides both the corresponding starting and ending byte indices of each codepoint yielded. The ending position is necessary to slice the original string when invalid UTF-8 bytes are converted into a Unicode replacement codepoint, since a single replacement codepoint can substitute anywhere from 1 to 3 invalid bytes (inclusive).

§Examples
use janetrs::JanetString;

let s = JanetString::new(b"\xE2\x98\x83\xFF\xF0\x9D\x9E\x83\xE2\x98\x61");

let chars: Vec<(usize, usize, char)> = s.char_indices().collect();
assert_eq!(chars, vec![
    (0, 3, '☃'),
    (3, 4, '\u{FFFD}'),
    (4, 8, '𝞃'),
    (8, 10, '\u{FFFD}'),
    (10, 11, 'a'),
]);
source

pub fn fields(&self) -> Fields<'_>

Available on crate feature unicode only.

Creates an iterator over the fields in a string, separated by contiguous whitespace.

§Example

Basic usage:

use janetrs::JanetString;

let s = JanetString::new("  foo\tbar\t\u{2003}\nquux   \n");
let fields: Vec<&[u8]> = s.fields().collect();
assert_eq!(fields, vec![
    "foo".as_bytes(),
    "bar".as_bytes(),
    "quux".as_bytes()
]);

A string consisting of just whitespace yields no elements:

use janetrs::JanetString;

assert_eq!(
    0,
    JanetString::new(&"  \n\t\u{2003}\n  \t").fields().count()
);
source

pub fn fields_with<F>(&self, f: F) -> FieldsWith<'_, F>
where F: FnMut(char) -> bool,

Creates an iterator over the fields in a string, separated by contiguous codepoints satisfying the given predicate.

If this string is not valid UTF-8, then the given closure will be called with a Unicode replacement codepoint when invalid UTF-8 bytes are seen.

§Example

Basic usage:

use janetrs::JanetString;

let s = JanetString::new("123foo999999bar1quux123456");
let fields: Vec<&[u8]> = s.fields_with(|c| c.is_numeric()).collect();
assert_eq!(fields, vec![
    "foo".as_bytes(),
    "bar".as_bytes(),
    "quux".as_bytes()
]);

A string consisting of all codepoints satisfying the predicate yields no elements:

use janetrs::JanetString;

assert_eq!(
    0,
    JanetString::new("1911354563")
        .fields_with(|c| c.is_numeric())
        .count()
);
source

pub fn grapheme_indices(&self) -> GraphemeIndices<'_>

Available on crate feature unicode only.

Creates an iterator over the grapheme clusters in this string along with their starting and ending byte index positions. If invalid UTF-8 is encountered, then the Unicode replacement codepoint is yielded instead.

§Examples

This example shows how to get the byte offsets of each individual grapheme cluster:

use janetrs::JanetString;

let s = JanetString::new("a\u{0300}\u{0316}\u{1F1FA}\u{1F1F8}");
let graphemes: Vec<(usize, usize, &str)> = s.grapheme_indices().collect();
assert_eq!(vec![(0, 5, "à̖"), (5, 13, "🇺🇸")], graphemes);
source

pub fn graphemes(&self) -> Graphemes<'_>

Available on crate feature unicode only.

Creates an iterator over the grapheme clusters in this string. If invalid UTF-8 is encountered, then the Unicode replacement codepoint is yielded instead.

§Examples

This example shows how multiple codepoints can combine to form a single grapheme cluster:

use janetrs::JanetString;

let s = JanetString::new("a\u{0300}\u{0316}\u{1F1FA}\u{1F1F8}");
let graphemes: Vec<&str> = s.graphemes().collect();
assert_eq!(vec!["à̖", "🇺🇸"], graphemes);

This shows that graphemes can be iterated over in reverse:

use janetrs::JanetString;

let s = JanetString::new("a\u{0300}\u{0316}\u{1F1FA}\u{1F1F8}");
let graphemes: Vec<&str> = s.graphemes().rev().collect();
assert_eq!(vec!["🇺🇸", "à̖"], graphemes);
source

pub fn lines(&self) -> Lines<'_>

Creates an iterator over all lines in a string, without their terminators.

For this iterator, the only line terminators recognized are \r\n and \n.

§Examples
use janetrs::JanetString;

let s = JanetString::new(
    &b"\
foo

bar\r
baz


quux"[..],
);
let lines: Vec<&[u8]> = s.lines().collect();
assert_eq!(lines, vec![
    &b"foo"[..],
    &b""[..],
    &b"bar"[..],
    &b"baz"[..],
    &b""[..],
    &b""[..],
    &b"quux"[..],
]);
source

pub fn lines_with_terminator(&self) -> LinesWithTerminator<'_>

Creates an iterator over all lines in a string, including their terminators.

For this iterator, the only line terminator recognized is \n. (Since line terminators are included, this also handles \r\n line endings.)

Line terminators are only included if they are present in the original string. For example, the last line in a string may not end with a line terminator.

Concatenating all elements yielded by this iterator is guaranteed to yield the original string.

§Examples
use janetrs::JanetString;

let s = JanetString::new(
    &b"\
foo

bar\r
baz


quux"[..],
);
let lines: Vec<&[u8]> = s.lines_with_terminator().collect();
assert_eq!(lines, vec![
    &b"foo\n"[..],
    &b"\n"[..],
    &b"bar\r\n"[..],
    &b"baz\n"[..],
    &b"\n"[..],
    &b"\n"[..],
    &b"quux"[..],
]);
source

pub fn sentence_indices(&self) -> SentenceIndices<'_>

Available on crate feature unicode only.

Creates an iterator over the sentences in this string along with their starting and ending byte index positions.

Typically, a sentence will include its trailing punctuation and whitespace. Concatenating all elements yielded by the iterator results in the original string (modulo Unicode replacement codepoint substitutions if invalid UTF-8 is encountered).

Since sentences are made up of one or more codepoints, this iterator yields &str elements. When invalid UTF-8 is encountered, replacement codepoints are substituted.

§Examples

Basic usage:

use janetrs::JanetString;

let s = JanetString::new(&b"I want this. Not that. Right now."[..]);
let sentences: Vec<(usize, usize, &str)> = s.sentence_indices().collect();
assert_eq!(sentences, vec![
    (0, 13, "I want this. "),
    (13, 23, "Not that. "),
    (23, 33, "Right now."),
]);
source

pub fn sentences(&self) -> Sentences<'_>

Available on crate feature unicode only.

Creates an iterator over the sentences in this string.

Typically, a sentence will include its trailing punctuation and whitespace. Concatenating all elements yielded by the iterator results in the original string (modulo Unicode replacement codepoint substitutions if invalid UTF-8 is encountered).

Since sentences are made up of one or more codepoints, this iterator yields &str elements. When invalid UTF-8 is encountered, replacement codepoints are substituted.

§Examples

Basic usage:

use janetrs::JanetString;

let s = JanetString::new(&b"I want this. Not that. Right now."[..]);
let sentences: Vec<&str> = s.sentences().collect();
assert_eq!(
    sentences,
    vec!["I want this. ", "Not that. ", "Right now.",]
);
source

pub fn split<'a, 'b, S>(&'a self, splitter: &'b S) -> Split<'a, 'b>
where S: ?Sized + AsRef<[u8]>,

Creates an iterator over substrings of this string, separated by the given string. Each element yielded is guaranteed not to include the splitter substring.

The splitter may be any type that can be cheaply converted into a &[u8]. This includes, but is not limited to, &str and &[u8].

§Examples

Basic usage:

use janetrs::JanetString;

let s = JanetString::from("Mary had a little lamb");
let x: Vec<&[u8]> = s.split(" ").collect();
assert_eq!(x, vec![
    &b"Mary"[..],
    &b"had"[..],
    &b"a"[..],
    &b"little"[..],
    &b"lamb"[..],
]);

let s = JanetString::from("");
let x: Vec<&[u8]> = s.split("X").collect();
assert_eq!(x, vec![&b""[..]]);

let s = JanetString::from("lionXXtigerXleopard");
let x: Vec<&[u8]> = s.split("X").collect();
assert_eq!(x, vec![
    &b"lion"[..],
    &b""[..],
    &b"tiger"[..],
    &b"leopard"[..]
]);

let s = JanetString::from("lion::tiger::leopard");
let x: Vec<&[u8]> = s.split("::").collect();
assert_eq!(x, vec![&b"lion"[..], &b"tiger"[..], &b"leopard"[..]]);

If a string contains multiple contiguous separators, you will end up with empty strings yielded by the iterator:

use janetrs::JanetString;

let s = JanetString::from("||||a||b|c");
let x: Vec<&[u8]> = s.split("|").collect();
assert_eq!(x, vec![
    &b""[..],
    &b""[..],
    &b""[..],
    &b""[..],
    &b"a"[..],
    &b""[..],
    &b"b"[..],
    &b"c"[..],
]);

let s = JanetString::from("(///)");
let x: Vec<&[u8]> = s.split("/").collect();
assert_eq!(x, vec![&b"("[..], &b""[..], &b""[..], &b")"[..]]);

Separators at the start or end of a string are neighbored by empty strings.

use janetrs::JanetString;

let s = JanetString::from("010");
let x: Vec<&[u8]> = s.split("0").collect();
assert_eq!(x, vec![&b""[..], &b"1"[..], &b""[..]]);

When the empty string is used as a separator, it splits every byte in the string, along with the beginning and end of the string.

use janetrs::JanetString;

let s = JanetString::from("rust");
let x: Vec<&[u8]> = s.split("").collect();
assert_eq!(x, vec![
    &b""[..],
    &b"r"[..],
    &b"u"[..],
    &b"s"[..],
    &b"t"[..],
    &b""[..]
]);

// Splitting by an empty string is not UTF-8 aware. Elements yielded
// may not be valid UTF-8!
let s = JanetString::from("☃");
let x: Vec<&[u8]> = s.split("").collect();
assert_eq!(x, vec![
    &b""[..],
    &b"\xE2"[..],
    &b"\x98"[..],
    &b"\x83"[..],
    &b""[..]
]);

Contiguous separators, especially whitespace, can lead to possibly surprising behavior. For example, this code is correct:

use janetrs::JanetString;

let s = JanetString::from("    a  b c");
let x: Vec<&[u8]> = s.split(" ").collect();
assert_eq!(x, vec![
    &b""[..],
    &b""[..],
    &b""[..],
    &b""[..],
    &b"a"[..],
    &b""[..],
    &b"b"[..],
    &b"c"[..]
]);

It does not give you ["a", "b", "c"]. For that behavior, use fields instead.

source

pub fn rsplit<'a, 'b, S>(&'a self, splitter: &'b S) -> SplitReverse<'a, 'b>
where S: ?Sized + AsRef<[u8]>,

Creates an iterator over substrings of this string, separated by the given string. Each element yielded is guaranteed not to include the splitter substring.

The splitter may be any type that can be cheaply converted into a &[u8]. This includes, but is not limited to, &str and &[u8].

§Examples

Basic usage:

use janetrs::JanetString;

let s = JanetString::from("Mary had a little lamb");
let x: Vec<&[u8]> = s.rsplit(" ").collect();
assert_eq!(x, vec![
    &b"lamb"[..],
    &b"little"[..],
    &b"a"[..],
    &b"had"[..],
    &b"Mary"[..],
]);

let s = JanetString::from("");
let x: Vec<&[u8]> = s.rsplit("X").collect();
assert_eq!(x, vec![&b""[..]]);

let s = JanetString::from("lionXXtigerXleopard");
let x: Vec<&[u8]> = s.rsplit("X").collect();
assert_eq!(x, vec![
    &b"leopard"[..],
    &b"tiger"[..],
    &b""[..],
    &b"lion"[..],
]);
let s = JanetString::from("lion::tiger::leopard");
let x: Vec<&[u8]> = s.rsplit("::").collect();
assert_eq!(x, vec![&b"leopard"[..], &b"tiger"[..], &b"lion"[..]]);

If a string contains multiple contiguous separators, you will end up with empty strings yielded by the iterator:

use janetrs::JanetString;

let s = JanetString::from("||||a||b|c");
let x: Vec<&[u8]> = s.rsplit("|").collect();
assert_eq!(x, vec![
    &b"c"[..],
    &b"b"[..],
    &b""[..],
    &b"a"[..],
    &b""[..],
    &b""[..],
    &b""[..],
    &b""[..],
]);

let s = JanetString::from("(///)");
let x: Vec<&[u8]> = s.rsplit("/").collect();
assert_eq!(x, vec![&b")"[..], &b""[..], &b""[..], &b"("[..]]);

Separators at the start or end of a string are neighbored by empty strings.

use janetrs::JanetString;

let s = JanetString::from("010");
let x: Vec<&[u8]> = s.rsplit("0").collect();
assert_eq!(x, vec![&b""[..], &b"1"[..], &b""[..]]);

When the empty string is used as a separator, it splits every byte in the string, along with the beginning and end of the string.

use janetrs::JanetString;

let s = JanetString::from("rust");
let x: Vec<&[u8]> = s.rsplit("").collect();
assert_eq!(x, vec![
    &b""[..],
    &b"t"[..],
    &b"s"[..],
    &b"u"[..],
    &b"r"[..],
    &b""[..]
]);

// Splitting by an empty string is not UTF-8 aware. Elements yielded
// may not be valid UTF-8!
let s = JanetString::from("☃");
let x: Vec<&[u8]> = s.rsplit("").collect();
assert_eq!(x, vec![
    &b""[..],
    &b"\x83"[..],
    &b"\x98"[..],
    &b"\xE2"[..],
    &b""[..]
]);

Contiguous separators, especially whitespace, can lead to possibly surprising behavior. For example, this code is correct:

use janetrs::JanetString;

let s = JanetString::from("    a  b c");
let x: Vec<&[u8]> = s.rsplit(" ").collect();
assert_eq!(x, vec![
    &b"c"[..],
    &b"b"[..],
    &b""[..],
    &b"a"[..],
    &b""[..],
    &b""[..],
    &b""[..],
    &b""[..],
]);

It does not give you ["a", "b", "c"].

source

pub fn splitn<'a, 'b, S>( &'a self, limit: usize, splitter: &'b S ) -> SplitN<'a, 'b>
where S: ?Sized + AsRef<[u8]>,

Creates an iterator of at most limit substrings of this string, separated by the given string. If limit substrings are yielded, then the last substring will contain the remainder of this string.

The needle may be any type that can be cheaply converted into a &[u8]. This includes, but is not limited to, &str and &[u8].

§Examples

Basic usage:

use janetrs::JanetString;

let s = JanetString::from("Mary had a little lamb");
let x: Vec<_> = s.splitn(3, " ").collect();
assert_eq!(x, vec![&b"Mary"[..], &b"had"[..], &b"a little lamb"[..]]);

let s = JanetString::from("");
let x: Vec<_> = s.splitn(3, "X").collect();
assert_eq!(x, vec![b""]);

let s = JanetString::from("lionXXtigerXleopard");
let x: Vec<_> = s.splitn(3, "X").collect();
assert_eq!(x, vec![&b"lion"[..], &b""[..], &b"tigerXleopard"[..]]);

let s = JanetString::from("lion::tiger::leopard");
let x: Vec<_> = s.splitn(2, "::").collect();
assert_eq!(x, vec![&b"lion"[..], &b"tiger::leopard"[..]]);

let s = JanetString::from("abcXdef");
let x: Vec<_> = s.splitn(1, "X").collect();
assert_eq!(x, vec![&b"abcXdef"[..]]);

let s = JanetString::from("abcdef");
let x: Vec<_> = s.splitn(2, "X").collect();
assert_eq!(x, vec![&b"abcdef"[..]]);

let s = JanetString::from("abcXdef");
let x: Vec<_> = s.splitn(0, "X").collect();
assert!(x.is_empty());
source

pub fn rsplitn<'a, 'b, S>( &'a self, limit: usize, splitter: &'b S ) -> SplitNReverse<'a, 'b>
where S: ?Sized + AsRef<[u8]>,

Creates an iterator of at most limit substrings of this string, separated by the given string. If limit substrings are yielded, then the last substring will contain the remainder of this string.

The needle may be any type that can be cheaply converted into a &[u8]. This includes, but is not limited to, &str and &[u8].

§Examples

Basic usage:

use janetrs::JanetString;

let s = JanetString::from("Mary had a little lamb");
let x: Vec<_> = s.rsplitn(3, " ").collect();
assert_eq!(x, vec![&b"lamb"[..], &b"little"[..], &b"Mary had a"[..]]);

let s = JanetString::from("");
let x: Vec<_> = s.rsplitn(3, "X").collect();
assert_eq!(x, vec![b""]);

let s = JanetString::from("lionXXtigerXleopard");
let x: Vec<_> = s.rsplitn(3, "X").collect();
assert_eq!(x, vec![&b"leopard"[..], &b"tiger"[..], &b"lionX"[..]]);

let s = JanetString::from("lion::tiger::leopard");
let x: Vec<_> = s.rsplitn(2, "::").collect();
assert_eq!(x, vec![&b"leopard"[..], &b"lion::tiger"[..]]);

let s = JanetString::from("abcXdef");
let x: Vec<_> = s.rsplitn(1, "X").collect();
assert_eq!(x, vec![&b"abcXdef"[..]]);

let s = JanetString::from("abcdef");
let x: Vec<_> = s.rsplitn(2, "X").collect();
assert_eq!(x, vec![&b"abcdef"[..]]);

let s = JanetString::from("abcXdef");
let x: Vec<_> = s.rsplitn(0, "X").collect();
assert!(x.is_empty());
source

pub fn utf8_chunks(&self) -> Utf8Chunks<'_>

Creates an iterator over chunks of valid UTF-8.

The iterator returned yields chunks of valid UTF-8 separated by invalid UTF-8 bytes, if they exist. Invalid UTF-8 bytes are always 1-3 bytes, which are determined via the “substitution of maximal subparts” strategy described in the docs for the to_str_lossy method.

§Examples
use janetrs::JanetString;

let s = JanetString::new(&b"foo\xFD\xFEbar\xFF"[..]);

let (mut valid_chunks, mut invalid_chunks) = (vec![], vec![]);
for chunk in s.utf8_chunks() {
    if !chunk.valid().is_empty() {
        valid_chunks.push(chunk.valid());
    }
    if !chunk.invalid().is_empty() {
        invalid_chunks.push(chunk.invalid());
    }
}

assert_eq!(valid_chunks, vec!["foo", "bar"]);
assert_eq!(invalid_chunks, vec![b"\xFD", b"\xFE", b"\xFF"]);
source

pub fn word_indices(&self) -> WordIndices<'_>

Available on crate feature unicode only.

Creates an iterator over the words in this string along with their starting and ending byte index positions.

This is similar to words_with_break_indices, except it only returns elements that contain a “word” character. A word character is defined by UTS #18 (Annex C) to be the combination of the Alphabetic and Join_Control properties, along with the Decimal_Number, Mark and Connector_Punctuation general categories.

Since words are made up of one or more codepoints, this iterator yields &str elements. When invalid UTF-8 is encountered, replacement codepoints are substituted.

§Examples

This example shows how to get the byte offsets of each individual word:

use janetrs::JanetString;

let s = JanetString::new(&b"can't jump 32.3 feet"[..]);
let words: Vec<(usize, usize, &str)> = s.word_indices().collect();
assert_eq!(words, vec![
    (0, 5, "can't"),
    (6, 10, "jump"),
    (11, 15, "32.3"),
    (16, 20, "feet"),
]);
source

pub fn words(&self) -> Words<'_>

Available on crate feature unicode only.

Creates an iterator over the words in this string. If invalid UTF-8 is encountered, then the Unicode replacement codepoint is yielded instead.

This is similar to words_with_breaks, except it only returns elements that contain a “word” character. A word character is defined by UTS #18 (Annex C) to be the combination of the Alphabetic and Join_Control properties, along with the Decimal_Number, Mark and Connector_Punctuation general categories.

Since words are made up of one or more codepoints, this iterator yields &str elements. When invalid UTF-8 is encountered, replacement codepoints are substituted.

§Examples

Basic usage:

use janetrs::JanetString;

let s = JanetString::new(&br#"The quick ("brown") fox can't jump 32.3 feet, right?"#[..]);
let words: Vec<&str> = s.words().collect();
assert_eq!(words, vec![
    "The", "quick", "brown", "fox", "can't", "jump", "32.3", "feet", "right",
]);
source

pub fn words_with_break_indices(&self) -> WordsWithBreakIndices<'_>

Available on crate feature unicode only.

Creates an iterator over the words and their byte offsets in this string, along with all breaks between the words. Concatenating all elements yielded by the iterator results in the original string (modulo Unicode replacement codepoint substitutions if invalid UTF-8 is encountered).

Since words are made up of one or more codepoints, this iterator yields &str elements. When invalid UTF-8 is encountered, replacement codepoints are substituted.

§Examples

This example shows how to get the byte offsets of each individual word:

use janetrs::JanetString;

let s = JanetString::new(&b"can't jump 32.3 feet"[..]);
let words: Vec<(usize, usize, &str)> = s.words_with_break_indices().collect();
assert_eq!(words, vec![
    (0, 5, "can't"),
    (5, 6, " "),
    (6, 10, "jump"),
    (10, 11, " "),
    (11, 15, "32.3"),
    (15, 16, " "),
    (16, 20, "feet"),
]);
source

pub fn words_with_breaks(&self) -> WordsWithBreaks<'_>

Available on crate feature unicode only.

Creates an iterator over the words in this string, along with all breaks between the words. Concatenating all elements yielded by the iterator results in the original string (modulo Unicode replacement codepoint substitutions if invalid UTF-8 is encountered).

Since words are made up of one or more codepoints, this iterator yields &str elements. When invalid UTF-8 is encountered, replacement codepoints are substituted.

§Examples

Basic usage:

use janetrs::JanetString;

let s = JanetString::new(&br#"The quick ("brown") fox can't jump 32.3 feet, right?"#[..]);
let words: Vec<&str> = s.words_with_breaks().collect();
assert_eq!(words, vec![
    "The", " ", "quick", " ", "(", "\"", "brown", "\"", ")", " ", "fox", " ", "can't", " ",
    "jump", " ", "32.3", " ", "feet", ",", " ", "right", "?",
]);
source

pub const fn as_raw(&self) -> *const u8

Return a raw pointer to the string raw structure.

The caller must ensure that the buffer outlives the pointer this function returns, or else it will end up pointing to garbage.

source

pub const fn as_ptr(&self) -> *const u8

Converts a string to a raw pointer.

The caller must ensure that the buffer outlives the pointer this function returns, or else it will end up pointing to garbage.

Trait Implementations§

source§

impl AsRef<[u8]> for JanetString<'_>

source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<BStr> for JanetString<'_>

source§

fn as_ref(&self) -> &BStr

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for JanetString<'_>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for JanetString<'_>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl DeepEq<JanetBuffer<'_>> for JanetString<'_>

source§

fn deep_eq(&self, other: &JanetBuffer<'_>) -> bool

source§

fn deep_ne(&self, other: &Rhs) -> bool

source§

impl DeepEq<JanetString<'_>> for JanetBuffer<'_>

source§

fn deep_eq(&self, other: &JanetString<'_>) -> bool

source§

fn deep_ne(&self, other: &Rhs) -> bool

source§

impl Default for JanetString<'_>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Display for JanetString<'_>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<&[u8]> for JanetString<'_>

source§

fn from(bytes: &[u8]) -> Self

Converts to this type from the input type.
source§

impl From<&JanetBuffer<'_>> for JanetString<'_>

source§

fn from(buff: &JanetBuffer<'_>) -> Self

Converts to this type from the input type.
source§

impl From<&JanetKeyword<'_>> for JanetString<'_>

source§

fn from(key: &JanetKeyword<'_>) -> Self

Converts to this type from the input type.
source§

impl From<&JanetString<'_>> for Janet

source§

fn from(val: &JanetString<'_>) -> Self

Converts to this type from the input type.
source§

impl From<&JanetString<'_>> for JanetBuffer<'_>

source§

fn from(s: &JanetString<'_>) -> Self

Converts to this type from the input type.
source§

impl From<&JanetString<'_>> for JanetKeyword<'_>

source§

fn from(string: &JanetString<'_>) -> Self

Converts to this type from the input type.
source§

impl From<&JanetString<'_>> for JanetSymbol<'_>

source§

fn from(string: &JanetString<'_>) -> Self

Converts to this type from the input type.
source§

impl From<&JanetSymbol<'_>> for JanetString<'_>

source§

fn from(sym: &JanetSymbol<'_>) -> Self

Converts to this type from the input type.
source§

impl From<&char> for JanetString<'_>

source§

fn from(ch: &char) -> Self

Converts to this type from the input type.
source§

impl From<&str> for JanetString<'_>

source§

fn from(rust_str: &str) -> Self

Converts to this type from the input type.
source§

impl From<JanetBuffer<'_>> for JanetString<'_>

source§

fn from(buff: JanetBuffer<'_>) -> Self

Converts to this type from the input type.
source§

impl From<JanetKeyword<'_>> for JanetString<'_>

source§

fn from(key: JanetKeyword<'_>) -> Self

Converts to this type from the input type.
source§

impl From<JanetString<'_>> for Janet

source§

fn from(val: JanetString<'_>) -> Self

Converts to this type from the input type.
source§

impl From<JanetString<'_>> for JanetBuffer<'_>

source§

fn from(s: JanetString<'_>) -> Self

Converts to this type from the input type.
source§

impl From<JanetString<'_>> for JanetKeyword<'_>

source§

fn from(string: JanetString<'_>) -> Self

Converts to this type from the input type.
source§

impl From<JanetString<'_>> for JanetSymbol<'_>

source§

fn from(string: JanetString<'_>) -> Self

Converts to this type from the input type.
source§

impl From<JanetSymbol<'_>> for JanetString<'_>

source§

fn from(sym: JanetSymbol<'_>) -> Self

Converts to this type from the input type.
source§

impl From<String> for JanetString<'_>

source§

fn from(s: String) -> Self

Converts to this type from the input type.
source§

impl From<Vec<u8>> for JanetString<'_>

source§

fn from(vec: Vec<u8>) -> Self

Converts to this type from the input type.
source§

impl From<char> for JanetString<'_>

source§

fn from(ch: char) -> Self

Converts to this type from the input type.
source§

impl<'a> FromIterator<&'a char> for JanetString<'_>

source§

fn from_iter<T: IntoIterator<Item = &'a char>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl<'a> FromIterator<&'a str> for JanetString<'_>

source§

fn from_iter<T: IntoIterator<Item = &'a str>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl<'a> FromIterator<&'a u8> for JanetString<'_>

source§

fn from_iter<T: IntoIterator<Item = &'a u8>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl FromIterator<String> for JanetString<'_>

source§

fn from_iter<T: IntoIterator<Item = String>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl FromIterator<char> for JanetString<'_>

source§

fn from_iter<T: IntoIterator<Item = char>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl FromStr for JanetString<'_>

§

type Err = Infallible

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl Index<i32> for JanetString<'_>

source§

fn index(&self, index: i32) -> &Self::Output

Get a reference to the byte of the string at the index.

It is more idiomatic to use bytes method.

§Janet Panics

Panics if the index is out of bounds.

§

type Output = u8

The returned type after indexing.
source§

impl JanetTypeName for JanetString<'_>

source§

fn name() -> String

Returns a string with the name of the type
source§

impl Ord for JanetString<'_>

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<'a, 'b> PartialEq<&'a [u8]> for JanetString<'_>

source§

fn eq(&self, other: &&'a [u8]) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<&'a BStr> for JanetString<'_>

source§

fn eq(&self, other: &&'a BStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<&'a BString> for JanetString<'_>

source§

fn eq(&self, other: &&'a BString) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<&'a str> for JanetString<'_>

source§

fn eq(&self, other: &&'a str) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<[u8]> for JanetString<'_>

source§

fn eq(&self, other: &[u8]) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<BStr> for JanetString<'_>

source§

fn eq(&self, other: &BStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<BString> for JanetString<'_>

source§

fn eq(&self, other: &BString) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<JanetKeyword<'_>> for JanetString<'_>

source§

fn eq(&self, other: &JanetKeyword<'_>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<JanetString<'_>> for &'a [u8]

source§

fn eq(&self, other: &JanetString<'_>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<JanetString<'_>> for &'a BStr

source§

fn eq(&self, other: &JanetString<'_>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<JanetString<'_>> for &'a BString

source§

fn eq(&self, other: &JanetString<'_>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<JanetString<'_>> for &'a str

source§

fn eq(&self, other: &JanetString<'_>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<JanetString<'_>> for [u8]

source§

fn eq(&self, other: &JanetString<'_>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<JanetString<'_>> for BStr

source§

fn eq(&self, other: &JanetString<'_>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<JanetString<'_>> for BString

source§

fn eq(&self, other: &JanetString<'_>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<JanetString<'_>> for JanetKeyword<'_>

source§

fn eq(&self, other: &JanetString<'_>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<JanetString<'_>> for JanetSymbol<'_>

source§

fn eq(&self, other: &JanetString<'_>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<JanetString<'_>> for String

source§

fn eq(&self, other: &JanetString<'_>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<JanetString<'_>> for Vec<u8>

source§

fn eq(&self, other: &JanetString<'_>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<JanetString<'_>> for str

source§

fn eq(&self, other: &JanetString<'_>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<JanetSymbol<'_>> for JanetString<'_>

source§

fn eq(&self, other: &JanetSymbol<'_>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<String> for JanetString<'_>

source§

fn eq(&self, other: &String) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<Vec<u8>> for JanetString<'_>

source§

fn eq(&self, other: &Vec<u8>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<str> for JanetString<'_>

source§

fn eq(&self, other: &str) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq for JanetString<'_>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialOrd<&'a [u8]> for JanetString<'_>

source§

fn partial_cmp(&self, other: &&'a [u8]) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a, 'b> PartialOrd<&'a BStr> for JanetString<'_>

source§

fn partial_cmp(&self, other: &&'a BStr) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a, 'b> PartialOrd<&'a BString> for JanetString<'_>

source§

fn partial_cmp(&self, other: &&'a BString) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a, 'b> PartialOrd<&'a str> for JanetString<'_>

source§

fn partial_cmp(&self, other: &&'a str) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a, 'b> PartialOrd<[u8]> for JanetString<'_>

source§

fn partial_cmp(&self, other: &[u8]) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a, 'b> PartialOrd<BStr> for JanetString<'_>

source§

fn partial_cmp(&self, other: &BStr) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a, 'b> PartialOrd<BString> for JanetString<'_>

source§

fn partial_cmp(&self, other: &BString) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd<JanetKeyword<'_>> for JanetString<'_>

source§

fn partial_cmp(&self, other: &JanetKeyword<'_>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a, 'b> PartialOrd<JanetString<'_>> for &'a [u8]

source§

fn partial_cmp(&self, other: &JanetString<'_>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a, 'b> PartialOrd<JanetString<'_>> for &'a BStr

source§

fn partial_cmp(&self, other: &JanetString<'_>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a, 'b> PartialOrd<JanetString<'_>> for &'a BString

source§

fn partial_cmp(&self, other: &JanetString<'_>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a, 'b> PartialOrd<JanetString<'_>> for &'a str

source§

fn partial_cmp(&self, other: &JanetString<'_>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a, 'b> PartialOrd<JanetString<'_>> for [u8]

source§

fn partial_cmp(&self, other: &JanetString<'_>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a, 'b> PartialOrd<JanetString<'_>> for BStr

source§

fn partial_cmp(&self, other: &JanetString<'_>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a, 'b> PartialOrd<JanetString<'_>> for BString

source§

fn partial_cmp(&self, other: &JanetString<'_>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd<JanetString<'_>> for JanetKeyword<'_>

source§

fn partial_cmp(&self, other: &JanetString<'_>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd<JanetString<'_>> for JanetSymbol<'_>

source§

fn partial_cmp(&self, other: &JanetString<'_>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a, 'b> PartialOrd<JanetString<'_>> for String

source§

fn partial_cmp(&self, other: &JanetString<'_>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a, 'b> PartialOrd<JanetString<'_>> for Vec<u8>

source§

fn partial_cmp(&self, other: &JanetString<'_>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a, 'b> PartialOrd<JanetString<'_>> for str

source§

fn partial_cmp(&self, other: &JanetString<'_>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd<JanetSymbol<'_>> for JanetString<'_>

source§

fn partial_cmp(&self, other: &JanetSymbol<'_>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a, 'b> PartialOrd<String> for JanetString<'_>

source§

fn partial_cmp(&self, other: &String) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a, 'b> PartialOrd<Vec<u8>> for JanetString<'_>

source§

fn partial_cmp(&self, other: &Vec<u8>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a, 'b> PartialOrd<str> for JanetString<'_>

source§

fn partial_cmp(&self, other: &str) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd for JanetString<'_>

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl TryFrom<Janet> for JanetString<'_>

§

type Error = JanetConversionError

The type returned in the event of a conversion error.
source§

fn try_from(value: Janet) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Eq for JanetString<'_>

Auto Trait Implementations§

§

impl<'data> Freeze for JanetString<'data>

§

impl<'data> RefUnwindSafe for JanetString<'data>

§

impl<'data> !Send for JanetString<'data>

§

impl<'data> !Sync for JanetString<'data>

§

impl<'data> Unpin for JanetString<'data>

§

impl<'data> UnwindSafe for JanetString<'data>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.