https://github.com/ulbora/rust_polymorphism
Rust example of polymorphism with trait element in struct calling trait method
https://github.com/ulbora/rust_polymorphism
dependency-injection polymorphism rust rust-lang
Last synced: about 1 month ago
JSON representation
Rust example of polymorphism with trait element in struct calling trait method
- Host: GitHub
- URL: https://github.com/ulbora/rust_polymorphism
- Owner: Ulbora
- Created: 2021-02-24T02:39:30.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-02-24T14:17:33.000Z (about 4 years ago)
- Last Synced: 2025-01-26T13:22:31.030Z (3 months ago)
- Topics: dependency-injection, polymorphism, rust, rust-lang
- Language: Rust
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Rust_Polymorphism
This design allows for dependency injection in Rust.
#### Here we are injecting a normal Server object into Wrapper and calling do_something()
```
let ms = MyServer {
test: String::from("test"),
};
let wr = Wrapper::::new(ms);
let rtn: bool = wr.do_something();```
#### Here we inject a MockServer object into Wrapper and call do_something()
```
let mwr = Wrapper::::new(MockMyServer {
test: String::from("mock test"),
});let rtn: bool = mwr.do_something();
```