Skip to content

Commit

Permalink
cosmos-sdk-proto: fix no_std + serde
Browse files Browse the repository at this point in the history
Adds some transforms which enable the generated PBJSON-related code to
be usable in `no_std` environments.

This is a workaround until such a time as it can be implemented natively
in `neoeinstein-prost-serde`. See neoeinstein/protoc-gen-prost#102.

Closes #499
  • Loading branch information
tony-iqlusion committed Sep 5, 2024
1 parent 28c05e8 commit 26bd4af
Show file tree
Hide file tree
Showing 105 changed files with 8,261 additions and 7,785 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/cosmos-sdk-proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
target: ${{ matrix.target }}
- run: cargo build --target ${{ matrix.target }} --release --no-default-features
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features grpc
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features serde

test:
runs-on: ubuntu-latest
Expand All @@ -49,3 +50,4 @@ jobs:
with:
toolchain: ${{ matrix.rust }}
- run: cargo test --release
- run: cargo test --all-features --release
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#[cfg(feature = "serde")]
impl serde::Serialize for Module {
#[allow(deprecated)]
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
fn serialize<S>(&self, serializer: S) -> core::result::Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
Expand Down Expand Up @@ -70,7 +70,7 @@ impl serde::Serialize for Module {
#[cfg(feature = "serde")]
impl<'de> serde::Deserialize<'de> for Module {
#[allow(deprecated)]
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
fn deserialize<D>(deserializer: D) -> core::result::Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
Expand Down Expand Up @@ -108,7 +108,7 @@ impl<'de> serde::Deserialize<'de> for Module {
}
#[cfg(feature = "serde")]
impl<'de> serde::Deserialize<'de> for GeneratedField {
fn deserialize<D>(deserializer: D) -> std::result::Result<GeneratedField, D::Error>
fn deserialize<D>(deserializer: D) -> core::result::Result<GeneratedField, D::Error>
where
D: serde::Deserializer<'de>,
{
Expand All @@ -119,13 +119,13 @@ impl<'de> serde::Deserialize<'de> for Module {

fn expecting(
&self,
formatter: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
formatter: &mut core::fmt::Formatter<'_>,
) -> core::fmt::Result {
write!(formatter, "expected one of: {:?}", &FIELDS)
}

#[allow(unused_variables)]
fn visit_str<E>(self, value: &str) -> std::result::Result<GeneratedField, E>
fn visit_str<E>(self, value: &str) -> core::result::Result<GeneratedField, E>
where
E: serde::de::Error,
{
Expand Down Expand Up @@ -156,11 +156,11 @@ impl<'de> serde::Deserialize<'de> for Module {
impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
type Value = Module;

fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn expecting(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
formatter.write_str("struct cosmos.app.runtime.v1alpha1.Module")
}

fn visit_map<V>(self, mut map_: V) -> std::result::Result<Module, V::Error>
fn visit_map<V>(self, mut map_: V) -> core::result::Result<Module, V::Error>
where
V: serde::de::MapAccess<'de>,
{
Expand Down Expand Up @@ -256,7 +256,7 @@ impl<'de> serde::Deserialize<'de> for Module {
#[cfg(feature = "serde")]
impl serde::Serialize for StoreKeyConfig {
#[allow(deprecated)]
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
fn serialize<S>(&self, serializer: S) -> core::result::Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
Expand All @@ -282,7 +282,7 @@ impl serde::Serialize for StoreKeyConfig {
#[cfg(feature = "serde")]
impl<'de> serde::Deserialize<'de> for StoreKeyConfig {
#[allow(deprecated)]
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
fn deserialize<D>(deserializer: D) -> core::result::Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
Expand All @@ -295,7 +295,7 @@ impl<'de> serde::Deserialize<'de> for StoreKeyConfig {
}
#[cfg(feature = "serde")]
impl<'de> serde::Deserialize<'de> for GeneratedField {
fn deserialize<D>(deserializer: D) -> std::result::Result<GeneratedField, D::Error>
fn deserialize<D>(deserializer: D) -> core::result::Result<GeneratedField, D::Error>
where
D: serde::Deserializer<'de>,
{
Expand All @@ -306,13 +306,13 @@ impl<'de> serde::Deserialize<'de> for StoreKeyConfig {

fn expecting(
&self,
formatter: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
formatter: &mut core::fmt::Formatter<'_>,
) -> core::fmt::Result {
write!(formatter, "expected one of: {:?}", &FIELDS)
}

#[allow(unused_variables)]
fn visit_str<E>(self, value: &str) -> std::result::Result<GeneratedField, E>
fn visit_str<E>(self, value: &str) -> core::result::Result<GeneratedField, E>
where
E: serde::de::Error,
{
Expand All @@ -330,11 +330,11 @@ impl<'de> serde::Deserialize<'de> for StoreKeyConfig {
impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
type Value = StoreKeyConfig;

fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn expecting(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
formatter.write_str("struct cosmos.app.runtime.v1alpha1.StoreKeyConfig")
}

fn visit_map<V>(self, mut map_: V) -> std::result::Result<StoreKeyConfig, V::Error>
fn visit_map<V>(self, mut map_: V) -> core::result::Result<StoreKeyConfig, V::Error>
where
V: serde::de::MapAccess<'de>,
{
Expand Down
Loading

0 comments on commit 26bd4af

Please sign in to comment.