-
-
Save rust-play/1352e3891e15756710d68c834da0a2b9 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait HeapSize { | |
fn heap_size(&self) -> usize; | |
} | |
pub struct KnownElementHeapSize<T>(pub T); | |
trait KnownHeapSize { | |
const S: usize; | |
} | |
impl KnownHeapSize for u8 { | |
const S: usize = 0; | |
} | |
impl <E: KnownHeapSize> HeapSize for KnownElementHeapSize<Vec<E>> { | |
fn heap_size(&self) -> usize { | |
self.0.capacity() * std::mem::size_of::<E>() + self.0.len() * E::S | |
} | |
} | |
fn main() { | |
println!("Hello, world!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment