Skip to content

Instantly share code, notes, and snippets.

@rebo
Created June 2, 2020 13:28
Show Gist options
  • Save rebo/1ceba84a9454fe11aeb1e43843b93177 to your computer and use it in GitHub Desktop.
Save rebo/1ceba84a9454fe11aeb1e43843b93177 to your computer and use it in GitHub Desktop.
struct RegisterId{
id: i32
}
struct FsValue {
value: String,
}
struct FsPointer{
value_at_mem_location:usize
}
#[derive(Default)]
struct PushHandler {
res : Vec<String>,
}
impl PushHandler {
fn push<T>(&mut self, val: T) where Self:OverloadablePush<T> {
self.overloaded_push( val);
}
}
// Overloaded Values:
trait OverloadablePush<T> {
fn overloaded_push(&mut self, val:T);
}
impl OverloadablePush<RegisterId> for PushHandler {
fn overloaded_push(&mut self, val:RegisterId){
self.res.push (format!("The register Id is {}", val.id))
}
}
impl OverloadablePush<FsValue> for PushHandler {
fn overloaded_push(&mut self, val:FsValue){
self.res.push(val.value);
}
}
impl OverloadablePush<FsPointer> for PushHandler {
fn overloaded_push(&mut self, val:FsPointer){
self.res.push(format!("I have accessed the filesystem of location: {}", val.value_at_mem_location));
}
}
fn main() {
let fs_value = FsValue { value : "A Value haha".to_string()};
let pointer = FsPointer{value_at_mem_location: 32};
let register_id = RegisterId{ id: 1337};
let mut push_handler = PushHandler::default();
push_handler.push(fs_value);
push_handler.push(pointer);
push_handler.push(register_id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment