GithubHelp home page GithubHelp logo

Comments (3)

nvksv avatar nvksv commented on July 21, 2024

I just updated the crate to version 0.2.1. The maybe attribute now can be applied to modules. E.g.:

crates.toml

[package]
name = "maybe-async-cfg-test-1"
version = "0.1.0"
edition = "2021"

[features]
sync = []
async = []
default = ["sync", "async"]

[dependencies]
maybe-async-cfg = "0.2.1"

main.rs

#[maybe_async_cfg::maybe(
    idents(hello_world(fn,keep)),
    sync(feature="sync",keep_self), 
    async(feature="async",self="async_")
)]
pub mod blocking {
  pub async fn hello_world() {
    todo!()
  }
}

fn main() {
    println!("Hello, world!");
}

now is expanding (cargo expand) into

#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
#[cfg(feature = "sync")]
pub mod blocking {
    pub fn hello_world() {
        ::core::panicking::panic("not yet implemented")
    }
}
#[cfg(feature = "async")]
pub mod async_ {
    pub async fn hello_world() {
        ::core::panicking::panic("not yet implemented")
    }
}
fn main() {
    {
        ::std::io::_print(::core::fmt::Arguments::new_v1(&["Hello, world!\n"], &[]));
    };
}

Earlier, this required reimport:

#[cfg(feature = "async")]
pub mod async_ftp {
    pub use crate::ftp::FtpStreamAsync as FtpStream;
}
#[cfg(feature = "sync")]
pub mod sync_ftp {
    pub use crate::ftp::FtpStreamSync as FtpStream;
}

Thank you for good idea!

from maybe-async-cfg.

quentinmit avatar quentinmit commented on July 21, 2024

Why does your example require specifying hello_world in idents?

I actually already implemented this as well... https://github.com/quentinmit/maybe-async-cfg/tree/mod

and I didn't find any need to specify idents.

from maybe-async-cfg.

nvksv avatar nvksv commented on July 21, 2024

Yes, if the name of hello_world should not change, it is not necessary to specify it in idents.

My mistake. Initially, I tested on the example when the hello_world was supposed to turn into a hello_world_async/hello_world_sync, and then quickly banned such renaming. But it would be more correct to delete idents(hello_world(fn)) entirely, as you noticed.

from maybe-async-cfg.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.