Editing
Rust
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Without Traits== This suffers from fixing the Rng to a specific implementation and prevents dependency inversion causing problems with things like testing and forcing any downstream users to be stuck with the choice. No one will have the option of using their quantum hardware random number generator now. extern crate rand; use rand::StdRng; pub struct Context { rng: StdRng, } impl Context { pub fn new() -> Context { let seed: &[_] = &[1, 2, 3, 4]; let mut rng = StdRng::from_seed(seed); } pub fn set_rng(&self, rng: StdRng) { self.rng = rng; } } impl SomeTrait for Context { //...Blah fn some_function(self) {} } fn use_context(ctx: &Context) { //...Blah } fn main() { let mut ctx = Context::new(); use_context(&ctx) }
Summary:
Please note that all contributions to Hegemon Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Hegemon Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
Edit source
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information