Skip to content

new or init function should probably be marked as unsafe #5

@ChocolateLoverRaj

Description

@ChocolateLoverRaj

Currently, there is no unsafe stopping someone from doing something like this:

let mut m1 = Mouse::new();
let mut m2 = Mouse::new();

// At the same time
m1.init();
m2.init();

Which would mess things up if the same ports are being accessed simultaneously.

I would suggest: making the init function unsafe:

/// # Safety
/// Reads and writes to ports 0x60 and 0x64. You must ensure that these ports are not being accessed concurrently by other code.

And another idea: What if the init function (and the other functions such as was a standalone function instead of being a method of Mouse? This way, we can leave Mouse as a pure, safe parser for incoming mouse data while making it more obvious that the init function modifies global state.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions