Closed eeeeeta closed 7 years ago
Thank you very much for this PR 🦀 I'll check it out and let you know if something has to be added/changed. Otherwise, I will merge it. Have a nice sunday!
@eeeeeta Can you implement From
from for OscType::Time
?
UPDATE The macro expects one parameter for variant match but two are required.
Manually implementing From
for OscType::Time
is straightforward and looks like this:
impl From<(u32, u32)> for OscType {
fn from(time: (u32, u32)) -> Self {
OscType::Time(time.0, time.1)
}
}
impl OscType {
#[allow(dead_code)]
pub fn time(self) -> Option<(u32, u32)> {
match self {
OscType::Time(sec, frac) => Some((sec, frac)),
_ => None,
}
}
}
Can you add this?
Don't we (also) want a std::time::Duration impl as well? I'll implement this when I get back to my computer, afk at the moment.
On 19 Mar 2017 13:01, "Andreas Linz" notifications@github.com wrote:
Manually implementing From for OscType::Time is straightforward and looks like this:
impl From<(u32, u32)> for OscType { fn from(time: (u32, u32)) -> Self { OscType::Time(time.0, time.1) } }impl OscType {
pub fn time(self) -> Option<(u32, u32)> {
match self {
OscType::Time(sec, frac) => Some((sec, frac)),
_ => None,
}
}
}
Can you add this?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/klingtnet/rosc/pull/1#issuecomment-287615156, or mute the thread https://github.com/notifications/unsubscribe-auth/AI959gzND-OvkaUTuu7qB11YIzaqd4Gmks5rnSc2gaJpZM4MhgQR .
Great Idea! But we may add a unit test for this conversion.
@klingtnet I've added the simple conversion you detailed above; let's just merge this PR for now, and I'll open another one when I get around to working out std::time::Duration
conversion and add some tests for that. (It looks to be quite finicky: OSC uses 1/232-second precision, whereas Rust uses nanoseconds, so we'll have to do some awkward conversion maths and add tests to check validity).
@eeeeeta Alright, I will merge this.
PS: I will push a new release to crates.io when From
is implemented for std::time::Duration
and maybe some others things were done.
This PR adds methods to get a value of a given type from an
OscType
enum without writing a tediousmatch
, and addsFrom
impls for everyOscType
variant. Furthermore,From<String>
andFrom<&str>
are now implemented forOscMessage
, to allow quickly making messages with just an address and no arguments.