feat: add smartstring

This commit is contained in:
2020-10-01 07:57:43 +08:00
parent 072dd9f9a4
commit e987a9de3b
4 changed files with 52 additions and 0 deletions

23
live-reload-rust/smartstring/Cargo.lock generated Normal file
View File

@@ -0,0 +1,23 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "smartstring"
version = "0.1.0"
dependencies = [
"smartstring 0.2.5",
]
[[package]]
name = "smartstring"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5579edba9651e6b9ccf0d516c4457521a149dadeb77e88b03eb1ae3183fe180a"
dependencies = [
"static_assertions",
]
[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"

View File

@@ -0,0 +1,10 @@
[package]
name = "smartstring"
version = "0.1.0"
authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
smartstring = "*"

View File

@@ -0,0 +1,8 @@
reference:
https://fasterthanli.me/articles/peeking-inside-a-rust-enum
PDF:
https://playsecurity.org/getdoc/3960_FF94A1BACA2F799268DB484102E074D0/Peeking%20inside%20a%20Rust%20enum.pdf

View File

@@ -0,0 +1,11 @@
use smartstring::{Compact, SmartString};
use std::mem::size_of_val;
fn main() {
let smart = SmartString::<Compact>::from("hello world");
dbg!(size_of_val(&smart));
let stand = String::from("hello world");
dbg!(size_of_val(&stand));
dbg!(size_of_val(&stand) + stand.capacity());
}