rust-ocpp icon indicating copy to clipboard operation
rust-ocpp copied to clipboard

First take on a no_std support

Open elrafoon opened this issue 2 years ago • 7 comments

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.

elrafoon avatar Aug 28 '23 09:08 elrafoon

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 avatar Aug 28 '23 10:08 tommymalmqvist

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;

tommymalmqvist avatar Aug 29 '23 11:08 tommymalmqvist

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

elrafoon avatar Sep 11 '23 11:09 elrafoon

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<T> or heapless::Vec<T,N> depending on std/no_std feature. Would you like this solution better? (I don't like it)

elrafoon avatar Sep 11 '23 11:09 elrafoon

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.

tommymalmqvist avatar Sep 18 '23 07:09 tommymalmqvist

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

Erk- avatar Oct 03 '23 09:10 Erk-

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.

tommymalmqvist avatar Oct 24 '23 05:10 tommymalmqvist

Closing this

tommymalmqvist avatar Nov 22 '24 20:11 tommymalmqvist