hi i am trying to write a rust music app as a complete noob i try to read different docs online but i am at a stop on this code
the play audio path is not found as it is also in src the code in it looks like this (second image)
plz be gentle even if i think my code looks like garbage
#get access to ~/Music directory
51 messages · Page 1 of 1 (latest)
the play_audio file i found online and i hope i can make it work with this code
thx for any help
you aren't declaring any modules
the //mod play_audio i experimented with ?
i will do search about how to declare thks
yes
mod is what allows you to use multiple code files in the same crate
then it tells me play_auido(&path) is not a fonction
because you're trying to call a module
when you want the function inside that module
so i need to use pub ? if i get that right ?
if you want an item to be visible in parent modules, it needs to be pub
maybe
is this a second mod play_audio inside of the other mod play_audio?
yeah xd i was going to say this feeled wrong xd
-modules
https://i.redd.it/1yy98srxyvx81.png
A full explanation of how to use Rust's module system can be found at
https://fasterthanli.me/articles/rust-modules-vs-files
Source for image
modules aren't functions
no in the file named play_audio the fonction is also named play_audio i tried to call it with this code
rn i am reading from the url this gentlemen sent me
if i am not mistaken this time the 2 directories are linked i just need to call the fonction now ?
thats how its doc told me to do?
i will do just mod play_audio; as suggested
// note: this is NOT idiomatic rust, we're just learning
// about mod.
is my english making me idiot because i didn't understand it wasn't a way of accomplishing the same result ?
it's a strictly worse way of accomplishing the same result
because modules still aren't functions
modules contain functions
yeah i need to call it
You do not put prints inside a module.
You put prints in functions, and put functions in modules.
yeah i was mistaken as some tuto told me do it like that and to add a fonction under pub mod
if i understand now here
(transposing on my files)
math is my file named play_audio.rs
and add is my fonction play_audio
sure
having a function named the same as the module might not be a good idea though
yeah i was arriving at that because after the docs say
to call the fonction
but it said the fonction is private
looking it up rn
then make that function not private
Change fn play_audio to pub fn play_audio
@fluid fog thats what i tried but we went for another way
I'm confused. What "another way"?
i added pub to my play_audio file and now it dont say to be private
but i think i missed something in docs so i will continue reading before anything
just
mod play_audio;
that has nothing to do with the visibility of the functions in the module
i mean pub before my fonction in play_audio.rs
like it is on rust lang.org
pub before a fonction make it public to the root
i just read again our discussion xd
no mod play_audio; was to make the module discoverable to main.rs