8 releases (4 breaking)

Uses new Rust 2024

0.7.9 Feb 23, 2025
0.7.8 Feb 23, 2025
0.6.6 Feb 22, 2025
0.5.6 Feb 22, 2025
0.3.5 Feb 16, 2025

#56 in No standard library

Download history 180/week @ 2025-02-12 481/week @ 2025-02-19 109/week @ 2025-02-26

770 downloads per month
Used in 2 crates

MIT/Apache

82KB
1.5K SLoC

Sew

Sew is a Rust library that provides a constant-size string with various manipulation methods, along with other unique string types. It is designed to be used in no_std environments and offers features like serialization, random string generation, and more.

Features

  • Constant-Size Strings: ConStr is a fixed-size character string structure that allows for efficient manipulation and querying.
  • Infallible Strings: InfallibleString can represent both valid and invalid UTF-8 sequences, useful for handling arbitrary byte sequences.
  • Pattern Searching: Implement custom pattern searching with the PatternSearcher trait, and more advanced modifications with the GetChar and GetSubStr traits.
  • Macros: Easily create ConStr instances with the new_cstr! macro.
  • Feature Flags:
    • serde: Enables serialization and deserialization support.
    • rand: Allows for random string generation.
    • expandable: Additional utilities for string manipulation.
    • unsafe_infallible: Provides unsafe mutable access to InfallibleString via DerefMut.

Installation

Add sew to your Cargo.toml:

[dependencies]
sew = { version = "0.7.7", features = ["full_unsafe"] }

Usage

Basic Usage

use sew::helpers::new_cstr;

fn main() {
    let x = new_cstr!("Hello, World!");
    println!("{}", x);
}

Features

Constant-Size Strings

ConStr provides a variety of methods for string manipulation:

  • new(): Create a new ConStr initialized with NUL characters.
  • len(): Get the length of the ConStr.
  • insert(), remove(), replace(): Modify the string content.
  • to_uppercase(), to_lowercase(): Change the case of the string.

Infallible Strings

InfallibleString can handle both valid and invalid UTF-8 sequences:

  • new_valid(): Create a valid InfallibleString.
  • new_invalid(): Create an invalid InfallibleString.
  • push_str(), push_byte(): Append content to the string.

Pattern Searching

Implement the PatternSearcher trait to define custom pattern matching logic, or GetChar or GetSubStr for advanced modification logic.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

This project is dual licensed under the MIT and Apache 2.0 Licenses.

Dependencies

~0–370KB