codelabsab / rust-ocpp

Libraries for ocpp 1.6 and 2.0.1
https://docs.rs/rust-ocpp/latest/rust_ocpp/
Apache License 2.0
64 stars 15 forks source link

First take on a no_std support #26

Open elrafoon opened 10 months ago

elrafoon commented 10 months ago

Hello,

I modified your nice library to support no_std environments.

It has some impact on std environment too, but maybe it could be worked out...

Would you be interested in reviewing and eventually merging no_std support?

Alternatively I can keep no_std version as in a standalone repo, but it seems to me as a waste of effort to maintain two crates when it could be one.

tommymalmqvist commented 10 months ago

Hello, this sounds very interesting. I have no experience in no_std support but will check your PR as soon as I can :)

Thanks!

tommymalmqvist commented 10 months ago

Hello, I can you rebase on the new code in main. Do you have any idea how to solve the the double Vec in lib.rs?

lib.rs

#[cfg(feature="std")]
 #[allow(type_alias_bounds)]
 pub type Vec<T: Sized, const N: usize> = std::vec::Vec<T>;

 #[cfg(feature="no_std")]
 pub use heapless::Vec;
elrafoon commented 10 months ago

Hello, sorry for my latency, I will look at that.

elrafoon commented 10 months ago

Does current implementation with double Vec cause any trouble? std::Vec is used in std builds, and heapless::Vec is used in no_std builds.

One think that I don't like is that all Vecs now must be supplied with generic constant N, which is then ignored by std::Vec in std builds.

Only other solution that comes to my mind are macros. We could use some macro throughout the library to instantiate either Vec or heapless::Vec<T,N> depending on std/no_std feature. Would you like this solution better? (I don't like it)

tommymalmqvist commented 9 months ago

Does current implementation with double Vec cause any trouble? std::Vec is used in std builds, and heapless::Vec is used in no_std builds.

One think that I don't like is that all Vecs now must be supplied with generic constant N, which is then ignored by std::Vec in std builds.

Only other solution that comes to my mind are macros. We could use some macro throughout the library to instantiate either Vec or heapless::Vec<T,N> depending on std/no_std feature. Would you like this solution better? (I don't like it)

Yes, the build is failing.

Erk- commented 9 months ago

One possible solution would be to select Vec when the features are any(all(feature = "std", not(feature = "no_std")), all(feature = "std", feature = "no_std")) and then make the heapless vec only be there if only no_std is enabled

tommymalmqvist commented 8 months ago

One possible solution would be to select Vec when the features are any(all(feature = "std", not(feature = "no_std")), all(feature = "std", feature = "no_std")) and then make the heapless vec only be there if only no_std is enabled

@elrafoon I think @Erk- suggestions is good. If you want to update your PR we can try it.