MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / from_string_truncate

Method from_string_truncate

crates/commitlog/src/varchar.rs:49–59  ·  view source on GitHub ↗

Move the given string into `Self` if its length does not exceed `N`, or truncate it to the appropriate length. In case of truncation, the resulting string may be shorter than `N` if `N` falls on a character boundary.

(s: String)

Source from the content-addressed store, hash-verified

47 /// In case of truncation, the resulting string may be shorter than `N` if
48 /// `N` falls on a character boundary.
49 pub fn from_string_truncate(s: String) -> Self {
50 if s.len() <= N {
51 Self { inner: s }
52 } else {
53 let mut s = s;
54 while s.len() > N {
55 s.pop().unwrap();
56 }
57 Self { inner: s }
58 }
59 }
60
61 /// Discard the `Varchar` wrapper.
62 pub fn into_inner(self) -> String {

Callers

nothing calls this directly

Calls 2

lenMethod · 0.45
unwrapMethod · 0.45

Tested by

no test coverage detected