Rust gods i need your help

why doesnt this work?
i made a library with "cargo new name --lib"
i added chrono in the toml file as a dependency
i added "use chrono::Utc;" at the top of the file
this example library only has one macro in it that prints out the current date using chrono in a certain format

for some reason the rust compiler says chrono is an unused import which is clearly false

also when im trying to use my library from a binary project the library and the macro inside it can be seen but i get an error of "use of undeclared type

A Conspiracy Theorist Is Talking Shirt $21.68

Ape Out Shirt $21.68

A Conspiracy Theorist Is Talking Shirt $21.68

  1. 2 weeks ago
    Anonymous

    Rust compiler can't evaluate imports from macros since they are compile time. If you don't use the macro, the import is never used either

    • 2 weeks ago
      Anonymous

      ah i see, and how can i make this work? because for what i need it has to be a macro

      • 2 weeks ago
        Anonymous

        Import chrono at calling site

      • 2 weeks ago
        Anonymous

        I don't use rust but probably just suppress the warning somehow.

        >Rust compiler can't evaluate imports
        >since they are compile time
        So what you're saying is that you rust doesn't support static linkage?

        No, if macro is not used, the statement in macro is never used either. The compiler can tell if a macro is ever called, but can't tell for functions because they can be called unconventionally. That's why everything inside a function is considered used

    • 2 weeks ago
      Anonymous

      >Rust compiler can't evaluate imports
      >since they are compile time
      So what you're saying is that you rust doesn't support static linkage?

      • 2 weeks ago
        Anonymous

        Macros has nothing to do with linkage, Anon.

        • 2 weeks ago
          Anonymous

          I don't use rust but probably just suppress the warning somehow.
          [...]
          No, if macro is not used, the statement in macro is never used either. The compiler can tell if a macro is ever called, but can't tell for functions because they can be called unconventionally. That's why everything inside a function is considered used

          thanks

    • 2 weeks ago
      Anonymous

      >Rust compiler can't evaluate imports
      >since they are compile time
      So what you're saying is that you rust doesn't support static linkage?

      I don't use rust but probably just suppress the warning somehow.
      [...]
      No, if macro is not used, the statement in macro is never used either. The compiler can tell if a macro is ever called, but can't tell for functions because they can be called unconventionally. That's why everything inside a function is considered used

      If you add pub use something; does it help? That's the newer syntax I think.

      dumb morons

  2. 2 weeks ago
    Anonymous

    Ignore all these other morons
    Just move the import inside the macro

    • 2 weeks ago
      Anonymous

      thanks anon you are amazing, its fixed in the library. but now when im using the library in a binary crate it says use of undeclared crate or module chrono. am i still missing something?

      • 2 weeks ago
        Anonymous

        One option might be to just expand the macro out to the full name without doing any use statements.

      • 2 weeks ago
        Anonymous

        Oh, shit
        I actually tried it out before I posted, and it worked fine, but I guess your setup is different
        Maybe it's better to use #[allow(unused_imports)] or whatever

        troony thread.
        If this was a genuine question it would be posted in /sqt/ or /dpt/ but it isn't.
        Trannies need the drama and attention.
        Do not reply to the troony thread.

        Yeah sure thanks for the advice

      • 2 weeks ago
        Anonymous

        The quickest fix is to make the binary crate depend on chrono. The macro more or less just copy/pastes code into the binary crate, so it doesn't get access to chrono automatically.
        A more sophisticated and arguably better solution is to do this:
        pub use chrono;

        #[macro_export]
        macro_rules! something {
        ... $crate::chrono::Utc::now() ...
        }
        This exposes chrono through the library crate. Let's say your library crate is called your_library, then thanks to the "pub use" your binary crate is able to do your_library::chrono::Utc::now(). And $crate is a magic variable that expands to your_library.

  3. 2 weeks ago
    Anonymous

    You're doing everything correctly
    It would seem you forgot to dilate your neovegana today, do that in front of your webcam and Mr. Shekelberg will unbrick your code

  4. 2 weeks ago
    sage

    troony thread.
    If this was a genuine question it would be posted in /sqt/ or /dpt/ but it isn't.
    Trannies need the drama and attention.
    Do not reply to the troony thread.

    • 2 weeks ago
      Anonymous

      nobody forced your hand to open this thread moron

  5. 2 weeks ago
    Anonymous

    >rust gods
    it's goddesses

    • 2 weeks ago
      Anonymous

      *xoddess, chud

  6. 2 weeks ago
    Anonymous

    By His grace, this entire thread must be purged.

    • 2 weeks ago
      Anonymous

      [...]

      troony thread.
      If this was a genuine question it would be posted in /sqt/ or /dpt/ but it isn't.
      Trannies need the drama and attention.
      Do not reply to the troony thread.

      Medication.

  7. 2 weeks ago
    Anonymous

    If you add pub use something; does it help? That's the newer syntax I think.

    • 2 weeks ago
      Anonymous

      no it didnt

  8. 2 weeks ago
    Anonymous

    just change Utc::now() to chrono::Utc::now()

  9. 2 weeks ago
    Anonymous

    What you need is to use the salt library, and wait until rust settles in.

  10. 2 weeks ago
    Anonymous

    What should I build in rust? I wanna learn shit

    • 2 weeks ago
      Anonymous

      Imageboard engine.

      • 2 weeks ago
        Anonymous

        >Imageboard engine.
        A good one. This could be actually fun.

        A doubly linked list

        Not that fun tbh

    • 2 weeks ago
      Anonymous

      A doubly linked list

    • 2 weeks ago
      Anonymous

      try to port https://winter.dev/articles/falling-sand-worlds to rust you will learn to hate/love rust depending on how good you are at software design.

  11. 2 weeks ago
    Anonymous

    Who designed this Syntax and thought it was good?

    • 2 weeks ago
      Anonymous

      >muh syntax
      dumb moronic LARPer

Your email address will not be published. Required fields are marked *