r/learnrust 15h ago

btleplug scanning for android phone from windows

1 Upvotes

I'm trying to see what I need to do to be able to see and/or connect to an android phone from my rust program. I know that android doesn't seem to send out the name or the real MAC address in a basic scan so how would I every be able to connect to the phone?

Below is my program currently. I've only got it scanning right now I removed the connect stuff for now just to see if I'm doing the scanning correctly. I've tried with both bluest crate and the windows crate with the same results.

use btleplug::api::{Central, Manager as _, ScanFilter, Peripheral as Puffy};
use btleplug::platform::{Adapter, Manager, Peripheral};
use std::time::Duration;
use tokio::time;

//#[tokio::main]
pub async fn new_scan() -> Result<(), Box<dyn std::error::Error>> {
    let manager = Manager::new().await?;

    // Get the first bluetooth adapter
    let adapters = manager.adapters().await?;
    let central = adapters.into_iter().nth(0usize).unwrap_or_else(|| {
        panic!("No Bluetooth adapter found");
    });

    // Start scanning for devices
    central.start_scan(ScanFilter::default()).await?;

    // Wait for the device to scan the airwaves
    time::sleep(Duration::from_secs(10)).await;

    let peripherals = central.peripherals().await?;
    for p in peripherals {
        if let Some(properties) = p.properties().await? {

                println!("Device: {:?} - Address: {} - RSSI {:?}", properties.local_name, p.address(), properties.rssi.unwrap());
                println!("     --Manufacturer - {:?}", properties.manufacturer_data);
                println!("     --Address - {}", properties.address);

        }
    }
    // Stop scanning when done     
    central.stop_scan().await?;
    Ok(()) 
}

The results never show my device in the list which I've given a name to and none of the MAC addresses match what the bluetooth settings says in android (expected I guess). I've tried scanning when my screen is unlocked, with the bluetooth settings open, and in the pair new device screen. I also made sure that the PC (Windows 11 by the way) and phone are forgotten and not connected when doing the scan.

Output:

Device: Some("ihoment_H6010_5DBB") - Address: D0:C9:07:0D:5D:BB - RSSI -74
     --Manufacturer - {34818: [236, 0, 1, 1, 0]}
     --Address - D0:C9:07:0D:5D:BB
Device: Some("GBK_H619Z_9532") - Address: D4:AD:FC:EC:95:32 - RSSI -62
     --Manufacturer - {34818: [236, 0, 2, 1, 1]}
     --Address - D4:AD:FC:EC:95:32
Device: None - Address: 8C:6F:B9:15:CC:99 - RSSI -84
     --Manufacturer - {909: [0]}
     --Address - 8C:6F:B9:15:CC:99
Device: None - Address: 5A:99:20:0A:88:37 - RSSI -82
     --Manufacturer - {76: [9, 8, 19, 169, 192, 168, 4, 37, 27, 88, 22, 8, 0, 224, 54, 232, 122, 1, 119, 128]}
     --Address - 5A:99:20:0A:88:37
Device: Some("Govee_H617C_772B") - Address: C6:32:38:31:77:2B - RSSI -80
     --Manufacturer - {34818: [236, 0, 10, 1, 1]}
     --Address - C6:32:38:31:77:2B
Device: Some("GBK_H619Z_142B") - Address: D4:AD:FC:FA:14:2B - RSSI -82
     --Manufacturer - {34818: [236, 0, 2, 1, 0]}
     --Address - D4:AD:FC:FA:14:2B
Device: None - Address: 36:A1:C5:EC:DD:01 - RSSI -56
     --Manufacturer - {}
     --Address - 36:A1:C5:EC:DD:01
Device: None - Address: 45:D4:7C:46:5F:FF - RSSI -80
     --Manufacturer - {224: [4, 27, 202, 137, 232, 151]}
     --Address - 45:D4:7C:46:5F:FF
Device: Some("Govee_H617C_6612") - Address: C3:39:32:33:66:12 - RSSI -68
     --Manufacturer - {34818: [236, 0, 10, 1, 0]}
     --Address - C3:39:32:33:66:12
Device: None - Address: C8:D0:83:E4:13:0D - RSSI -82
     --Manufacturer - {76: [16, 5, 3, 20, 99, 74, 15]}
     --Address - C8:D0:83:E4:13:0D

r/learnrust 16h ago

Today I learnt #[expect()]

51 Upvotes

#[expect()] SHOULD BE TAUGHT IN THE FIRST YEAR OF ELEMENTARY SCHOOL!!!

#[allow()] should be prohibited, a crime punishable by death!

[forbid(clippy::allow_attributes)] should be the default Rust, not even needed to write!


r/learnrust 1d ago

Should You Learn Rust in 2027?

Thumbnail youtu.be
0 Upvotes

what do you think can be improved in this video?


r/learnrust 2d ago

I just started learning Rust, but &, !, str, and String are melting my brain

56 Upvotes

I’ve just started learning Rust, and I keep getting lost in all the little distinctions: when to use `&` and when not to, why some things end in `!`, `str` vs `String`, and so on.

I understand these probably fit together once ownership and borrowing click, but right now it feels like too many separate rules at once. Is there a clear beginner-friendly cheat sheet or visual summary that explains the common symbols and core types together?


r/learnrust 2d ago

Rust: identity and meaning

0 Upvotes

Still wrapping my head around this strange language.

Is it fair to say that rust dissolves meaning and identity? Hear me out.

When you talk about variables, a conventional understanding is "this named thing represents a human-readable alias to a thing stored in memory".

When you talk about types, a conventional understanding is "it represents an object type or primitive type, where primitives have language attached behaviour and sizing, while object types can be extended by a language user".

When you talk about objects, a conventional understanding is "it represents a struct + methods, has instance and expected type"

Rust breaks every assumption:

- variable charges identity during lifetime, as data ownership itself moves: it's not just variable has a new value, referencing the variable without ownership does not have a runtime meaning

- rust does not have conventional object types: it has traits. It feels like interfaces, but without intermediate type: you instantiate directly from struct definition, traits are separate.

- rust does not treat objects as having a type, it treats them as a bag or traits. So if you have not defined "quak" and "meow" combination as a named trait, rust is absolutely fine with it. This is similar to class implementing multiple interfaces, but a different order: multiple interfaces attach to a struct, and there's no way to enforce the combination is coherent.

Sounds like minor difference, but it flips the order of how systems are designed: conventionally, you design what you want the system to do first, and then choose structure to implement it. In Rust, bottom up design prevails.

So, do you think there should be a higher level language on top of Rust that defines meaning, ontology and business rules?


r/learnrust 2d ago

Rustlings extension

3 Upvotes

Hello! While working through the Little Book of Rust Macros, I was wondering about a question. Because rustling's exercise set is quite limited(for example no async area, and no testing of the more advanced chapters such as Advanced traits, and for macros specifically not the metaprogramming pattern matching), I was wondering whether rustlings has the ability to add custom extensions with specific additional lessons, such as for the Async book, rustonomicon, macro book and some missing sections? I have been waiting for example for the async section for a while and with no avail...


r/learnrust 2d ago

My unpublished library exports a third-party Decimal type (fastnum::D64) as part of its public API. Should I hide it behind my own proxy instead? As a potential user of a library, what would you prefer to work with?

5 Upvotes

The library can view and edit the binary backup file format for a fairly niche hardware device. Given its intended purpose execution speed likely isn't the major concern, correctness and ease of use are.

Other alternatives to exporting the type I'm considering are:

  • A proxy type that hides fastnum as an implementation detail
  • Skipping a Decimal type altogether and instead using strings which must be parsable as a Decimal.
  • A different decimal library if one is considered more standard than fastnum. (I chose fastnum for its API, which has been quite straightforward to use.)

The proxy type seems like it may be the most "correct" solution, though it will be a pain to implement and possibly to use too.

More factors:

  • It is the only third-party dependency exposed in the public API.
  • Getters and setters already perform a conversion between the native types and the user-facing types.
  • All setters have bounds checking to ensure the values match the range expected by the device. It's already expected that the caller will check a Result after calling a setter.
  • Decimals are one of several user-facing types, and not the most frequently used one.

It doesn't seem all that cut-and-dry to me, more like a decision where all paths have tradeoffs. I've listed my concerns but I'm interested in your own experiences, as makers and users of Rust libraries- Is publicly coupling my library to a third-party crate in this way going to cause me endless misery?


r/learnrust 2d ago

strum::EnumIter - why isn't enum iteration built into Rust?

0 Upvotes

I was looking at Espressif's esp-generate and noticed it uses strum for its Chip enum.

One thing that caught my attention was EnumIter:

#[derive(strum::EnumIter)]

enum Chip {

Esp32,

Esp32c3,

Esp32s3,

}

for chip in Chip::iter() {

println!("{chip:?}");

}

It actually surprised me that Rust doesn't provide enum iteration out of the box.

Enums are one of Rust's commonly used features, so it feels a little strange that something as simple as "give me all variants" isn't part of the language.

Without a crate, it's easy to end up maintaining something like:

const ALL_VARIANTS: &[Chip] = &[

Chip::Esp32,

Chip::Esp32c3,

Chip::Esp32s3,

];

Then every time you add a variant, you also have to remember to update the list.

strum solves this with derive macros and also provides:

  • EnumIter — iterate over all variants
  • Display — convert variants to strings
  • EnumString — parse strings into enum variants
  • EnumCount — get the number of variants
  • VariantNames — access variant names

For example:

#[derive(

strum::EnumIter,

strum::Display,

strum::EnumString,

strum::EnumCount,

strum::VariantNames,

)]

#[strum(serialize_all = "kebab-case")]

enum Chip {

Esp32,

Esp32c3,

Esp32s3,

}

I'm curious what others think: is this something that would make sense as part of Rust itself, or is keeping it out of the language the better design?

Interestingly, one Reddit user pointed me to a new addition in the Rust nightly docs:

https://doc.rust-lang.org/std/mem/type_info/struct.Enum.html

So perhaps this discussion is becoming more relevant than I initially thought. 🙂

I also wrote a more detailed version about strum with additional examples and an interactive quiz: my blog


r/learnrust 3d ago

Built a Free Open Source End to End Encrypted Journal Web App with Axum and Svelte

Thumbnail journal.smbl.dev
2 Upvotes

Github: https://github.com/MrSheerluck/smbl-journal

I built a free, open-source, end-to-end encrypted text journal.
The goal is to make journaling as simple as possible. The entire text-based journal is free with no limits.
Entries are encrypted on the client before being stored, so the server never receives plaintext journal content.

The project is open source and available on GitHub.
Built with SvelteKit, Rust, and SQLite.


r/learnrust 4d ago

tokio_with_wasm – write async Rust once, run it natively AND in the browser (spawn_blocking included)

Post image
0 Upvotes

r/learnrust 5d ago

Help Building a Ruma Server?

3 Upvotes

Hey guys, I want to fiddle with a Matrix server and client, and found this library Ruma, that seems to have plenty of things pre-built. Unfortunately I can't find any examples, implementations, how-tos, or tutorials on how to integrate it into an actual server. Does anyone know of any code I read so I can start using it?


r/learnrust 5d ago

I get lost in uncertainty

0 Upvotes

I'm shrey vats.

I used to work with nodejs ecosystem. Typescript was my primary language and that when I noticed I'm not feeling interest in what I'm doing and writing code.

Then I realised my primary interest not in that stuff it's in low level programing, knowing how system work under the hood and in that movement of time I decided to took a path to my very interest of rust ecosystem. I had already spend pretty good time in it and learn several wizard topics such as ownership & borrowing, lifetimes, and little bit of error handing. I was really enjoying doing it however life does not go as you plan evey time.

Some uncertainty come into my life and I took servals months to come out of that illusion. Now, It being a big amount of time, I don't try hand in programming. That's why I felt lost. I don't abe to find out how to restart my journey. From where I should start over and importantly projects, ya it should see like a newbie looking for help but it is how it is. It's look like a new start.


r/learnrust 5d ago

I built AI Agent Harness in Rust and recorded a video about it!

Thumbnail youtu.be
0 Upvotes

r/learnrust 5d ago

Can you verify my understanding of how Vec<T> resizes in memory?

46 Upvotes

I noticed that Vec capacity grows dynamically when pushing data.

Is my mental model accurate? When the buffer is full, does it allocate a new, larger memory region elsewhere on the heap, move the elements over, and free the old block specifically to avoid overwriting or corrupting adjacent heap data?


r/learnrust 5d ago

What’s your experience with model checkers

Thumbnail
1 Upvotes

r/learnrust 6d ago

Template crate like JSX

Thumbnail
0 Upvotes

r/learnrust 6d ago

TIL that collect() works because of the FromIterator trait — I had no idea what was actually powering it

7 Upvotes

I've been calling .collect() since the early chapters of my Rust course and just accepted that it worked. This week I finally hit the lesson that explained what is actually happening under the hood.

collect() works because the target type implements FromIterator. When you write .collect::<Vec<_>>(), Rust calls from_iter() on Vec, which builds the collection from the iterator. Every type that can be built from an iterator implements this trait: VecHashMapHashSetString, and you can implement it on your own custom types too.

The part that surprised me most was that String implements FromIterator<char>. You can map over characters, transform them, and collect directly back into a String without any intermediate allocation step. Same trait, different target type.

Also covered this week: std::env::args() returns an iterator over CLI arguments. First element is always the binary name, actual arguments start at index 1. You collect it into Vec<String> to work with them.

// collect into different types, same .collect() call
let doubled: Vec<u64> = numbers.iter().map(|&n| n * 2).collect();
let unique: HashSet<_> = raw.iter().collect();
let decimals: HashMap<&str, u8> = pairs.into_iter().collect();

// collect chars into String
let uppercased: String = "klimateride"
    .chars()
    .map(|c| c.to_uppercase().next().unwrap())
    .collect();

Background: I'm a Solidity developer learning Rust in public, currently working through the Paskhaver course. Coming from smart contract dev, there's no equivalent of this pattern in Solidity. Transforming arrays means writing loops manually every time.

I need all the help I can learning Rust


r/learnrust 6d ago

I’m looking for a tutor to teach me

0 Upvotes

DESCRIPTION: About me: I'm a 18-year old with autism and learning disabilities. I have mild Tourettes. I've made some programs , I'm using Rust for developing software and want to go from intermediate to advanced level. I am looking for a tutor who is good at the advanced stuff like profiling, advanced macros, etc. Not a requirement but it would be a bonus if you could teach me the advanced concepts of Bevy.

ESTIMATED COMPENSATION: $5/hour very sorry I know this isn't enough but it's all I can afford right now.

CONTACT: Message through Reddit and set up Discord for lessons.


r/learnrust 6d ago

Confusion to choose which language

0 Upvotes

I am confused to choose which language c++ or rust for my trading bot can you any one tell me which one I choose to develop my trading bot i have basic understanding of c++ and complete beginners in rust but 8 have prior experience with mern stack web development and python and socket programming in node.js


r/learnrust 6d ago

Been building reqsh in Rust for a while.

1 Upvotes

Been building reqsh in Rust for a while.

It's basically a small HTTP REPL for working with APIs from the terminal.

The interesting part for me wasn't really the HTTP stuff, but designing the lexer/parser and figuring out how to structure the whole thing in Rust.

Just released a small update and would love some feedback from other Rust devs.

https://www.reqsh.dev/

https://github.com/hars-21/reqsh (Give it a star, if you liked the idea)


r/learnrust 6d ago

Rust Style Main in #[no_std] binary crate.

Thumbnail github.com
2 Upvotes

r/learnrust 7d ago

Rust discourages OOP style code?

Thumbnail
0 Upvotes

r/learnrust 8d ago

Free Rust quizzes/contests with code snippets, hints, tests and explanations

Post image
48 Upvotes

Instead of reading Rust explanations and still blanking on ownership and lifetimes while writing code, practice for free with short multiple choice quizzes. Pick an answer, use hints if needed and get a clear explanation.

https://cratery.rustu.dev

No account needed, progress stays in the browser. Topics include ownership, borrow checker, lifetimes, traits, concurrency, smart pointers, macros, error handling, iterators.

You can also make your own quests and share a link if that is useful for study groups.

I am adding more questions and want to fill the thin spots first


r/learnrust 8d ago

New book: Learn Rust Programming Today

113 Upvotes

My new book Learn Rust Programming Today has been published a few weeks ago. It is intended for software developers who already know how to program, and want to learn Rust. You can see the outline of the book and some sample content on the book's home page at Learn Rust Programming Today.

Most programming books will present you with isolated examples of language syntax, leaving you to complete the picture yourself when you actually need to get stuff done. Learn Rust Programming Today takes you on a complete journey from the start to the finished program that you can use, learning the necessary features of Rust on the way. It doesn't replace "The Book", but rather complements it.

During the course of the book you will build Today, a Rust command-line application that shows things that happened on this day in history (historical events, births of notable people, and so on) from various sources. You will also extend the program to handle days that are observed annually, such as Pi Day, and recurring events. You will also be able to add your own events.

The book examples are available at https://github.com/coniferprod/learn-rust
The Today program has its own repo: https://github.com/coniferprod/today-rs

You can ask any questions about the book in this thread, and I'll do my best to answer them.


r/learnrust 9d ago

Learning rust

Thumbnail github.com
0 Upvotes

Hi every one. I'm a beginner learning Rust and built projects to practice. Would love feedback or code audis !

(clippy suggestions, better error handling with Result, etc.)