-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Traits for abstract objects #5
Conversation
I'd like to use these object like this: let client = Ctx::new_with_port("127.0.0.1", 502).unwrap();
let myCoil = client.coil(0x0F3);
let res = myCoild.test().unwrap();
myCoild.toggle().unwrap(); I don't know how to implement this in a good way. Could you give me some hints? |
Thank you for your contribution. enum DropFunction {
SwitchOn(Coil),
SwitchOff(Coil),
Toggle(Coil)
}
impl Drop for DropFunction {
// ...
}
let myCoil = DropFunction::SwitchOff(client.coil(0x0F3));
// coil gets switched off after leaving the current scope BTW: I don't like the name |
I totally agree! I just had no idea for a good name ;-) |
1d75cfe
to
5d9b47b
Compare
Do you have any ideas for a good name? |
Hmm, good question and I must confess, that I also used the word The question is, how to merge the two functionalities of scoped and normal objects? |
I see. I did not look at the scoped objects yet. |
what about |
No, I wanted to say, that the name struct Coil {
address: ....
}
struct ScopedCoil {
coil: Coil,
fun: CoilDropFuction
}
trait Coil {
fn new() { ... }
fn toggle() { ... }
}
trait ScopedCoil: Coil {
fn new() { ... }
}
impl Drop for ScopedCoil { .... } |
I'd like to do s.th. like this: let mut client = tcp::Transport::new("192.168.0.100").unwrap();
let ro_bit = objects::RoBit::new(&mut client, 0x0120);
let rw_bit = objects::RwBit::new(&mut client, 0x0420);
match ro_bit.test() {
Err(err) => {},
Ok(state) => match state {
Coil::On=> rw_bit.set(),
Coil::Off=> rw_bit.clear()
}
} But that does not work, because I need a mutable reference of |
...with the current draft it would look like this: let mut client = tcp::Transport::new("192.168.0.100").unwrap();
let ro_bit = RoBit::new(0x02);
let rw_bit = RwBit::new(0x03);
let x = ro_bit.test(&mut client).unwrap();
println!("RoBit: {:?}",x);
let y = rw_bit.test(&mut client).unwrap();
println!("RwBit: {:?}",y);
rw_bit.toggle(&mut client).unwrap();
let z = rw_bit.test(&mut client).unwrap();
println!("RwBit: {:?}",z); |
I think we should stay in the Modbus domain with the naming (Coil, Register...) because that's what people expect and understand when they know Modbus. I also don't see any benefit in your OO approach to the freestanding functions for |
I agree, I just had no other name for it to play around with ;-)
there is no real benefit as long as we don't hold a reference of the client within the objects. But we cannot do this because the reference needs to be mutable :-\
Just add it's functions? |
I think we can close this :) |
No description provided.