An open API service indexing awesome lists of open source software.

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

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();

```