Skip to content

Step 1.6: Static and dynamic dispatch#7

Open
ziimakc wants to merge 2 commits intomainfrom
1_6_dispatch
Open

Step 1.6: Static and dynamic dispatch#7
ziimakc wants to merge 2 commits intomainfrom
1_6_dispatch

Conversation

@ziimakc
Copy link
Owner

@ziimakc ziimakc commented Jan 26, 2026

Resolves Step 1.6

Task

Given the following Storage abstraction and User entity:

trait Storage<K, V> {
    fn set(&mut self, key: K, val: V);
    fn get(&self, key: &K) -> Option<&V>;
    fn remove(&mut self, key: &K) -> Option<V>;
}

struct User {
    id: u64,
    email: Cow<'static, str>,
    activated: bool,
}

Implement UserRepository type with injectable Storage implementation, which can get, add, update and remove User in the injected Storage. Make two different implementations: one should use [dynamic dispatch][2] for Storage injecting, and the other one should use [static dispatch][1].

Solution

Implement UserRepository type with injectable Storage using static and dynamic dyspatch for storage. Add usage example and test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant