Skip to content

Commit

Permalink
string-wrapper: add Copy, Default, and is_empty
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Oct 29, 2015
1 parent 69adf14 commit 5cbc84d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "string-wrapper"
version = "0.1.1"
version = "0.1.2"
authors = ["Simon Sapin <simon.sapin@exyr.org>"]
license = "MIT"
repository = "https://github.com/SimonSapin/rust-std-candidates"
Expand Down
6 changes: 5 additions & 1 deletion lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::str;
/// Like `String`, but with a fixed capacity and a generic backing bytes storage.
///
/// Use e.g. `StringWrapper<[u8; 4]>` to have a string without heap memory allocation.
#[derive(Clone)]
#[derive(Clone, Copy, Default)]
pub struct StringWrapper<T> where T: Buffer {
len: usize,
buffer: T,
Expand Down Expand Up @@ -60,6 +60,10 @@ impl<T> StringWrapper<T> where T: Buffer {
self.len
}

pub fn is_empty(&self) -> bool {
self.len == 0
}

/// Users must ensure that the string remains well-formed UTF-8.
pub unsafe fn set_len(&mut self, new_len: usize) {
self.len = new_len
Expand Down

0 comments on commit 5cbc84d

Please sign in to comment.