-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
rust: no_std support #148
rust: no_std support #148
Conversation
…td::io and embedded_io
Thank you for the PR @Sympatron. no_std support is here earlier than I anticipated. :) Let me take a look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thanks for the PR.
rust/src/channel/mod.rs
Outdated
pub use unix_channel::UnixChannel; | ||
|
||
use crate::osdp_sys; | ||
use crate::{osdp_sys, Mutex}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we have an explicit
#[cfg(feature = "std")]
use parking_lot::Mutex;
#[cfg(not(feature = "std"))]
use spin::Mutex;
insread of importing from crate::? It's confusing as it appears as though we are providing a mutex type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. This feels wrong. I wanted to have the Mutex
selection only in one place, but I agree this was not the best solution.
I solved this now, by using Arc
instead of Mutex
in lib.rs
.
@@ -183,4 +178,5 @@ impl Drop for PeripheralDevice { | |||
} | |||
} | |||
|
|||
#[cfg(feature = "std")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can have a no_std compliant file implementation as well. Was this left out just for simplicity or is there a design problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know of any way to solve this generally without std
so I left it out. I think it would make more sense to let the user handle that themselves in the command callback.
I am in the middle of the -sys crate split. I guess it makes sense to merge this and then do the split (otherwise this branch would have way too many conflicts). I will fix any fallouts from this change post merge since no one is using this create ATM. |
Sounds good. I just pushed a fix to your comment about |
The Rust crate currently depends heavily on
std
. Since OSDP is a protocol mostly for embedded devices I thinkno_std
support is necessary.This PR adds that support by:
core::*
andalloc::*
types instead ofstd::*
where possible."std"
, which users can opt out of. Things likeUnixChannel
or thefile
API will not be available then.parking_log
andspin
as a replacement forstd::sync::Mutex
. I choseparking_lot
, because it is widely used, cross platform and supportslock_api
and can therefore be used just likespin::Mutex
forno_std
without any changes. The use ofspin
should be temporary, because this is almost never what you really want. In the future we should probably let the user choose the concreteMutex
implementation that makes sense for their platform. I didn't do this, because I wanted to keep the changes backwards compatible for now.Read
andWrite
traits instead ofstd::io::{Read, Write}
, because the latter is notno_std
compatible. I couldn't just replace them withembedded_io::{Read, Write}
either, because those are not object safe and can therefore not be used withBox<dyn ...>
. My traits are just very thin wrappers around the others with blanket implementations for everything implementingstd::io::{Read, Write}
orembedded_io::{Read, Write}
.I am open for discussion about my decisions in this PR. :)