[][src]Crate ro

R/O

Project

Features

This crate helps make stuff read-only.

Inconvenient builder pattern

An example with builder pattern:

  • You make new struct with all fields private.

  • For each field, you might want to add 2 functions:

    • set_x(&mut self, ...): to change the field's value.
    • get_x(&self, ...): to access the field's value.

That works fine if your struct has several private fields. But it will be inconvenient when you add more and more fields: for each field, there's a chance that you will need to add 2 more functions. The more public API, the more you will have to maintain.

ReadOnly

This struct can help shortening your code:

  • You can make any of your struct's fields public.
  • Then you can implement Default. This could help your users with what you think good default values should be. And then they can adjust those values as they wish.
  • Your code can freely accepts your own struct, and converts it into a read-only version. Then you can wrap that version inside an Arc, and share it across threads without worrying about Arc::get_mut().
  • Even in case your struct has some mutable functions, the read-only version still does it job well: mutable functions are not accessible.

Notes

The author belives that this crate should be used in binary programs, not in library crates. ReadOnly itself is extremely simple to code. The author thinks it would help your library's users a lot if you try not to include this crate as a dependency in your own libraries.

But, it's your choice.

Modules

version_info

0.1.0 (July 7th, 2019)

Structs

ReadOnly

Read-only container

Constants

CODE_NAME

Crate code name

ID

ID of this crate

NAME

Crate name

RELEASE_DATE

Crate release date (year/month/day)

TAG

Tag, which can be used for logging...

VERSION

Crate version