Struct rosu_map::Beatmap

source ·
pub struct Beatmap {
Show 42 fields pub format_version: i32, pub audio_file: String, pub audio_lead_in: f64, pub preview_time: i32, pub default_sample_bank: SampleBank, pub default_sample_volume: i32, pub stack_leniency: f32, pub mode: GameMode, pub letterbox_in_breaks: bool, pub special_style: bool, pub widescreen_storyboard: bool, pub epilepsy_warning: bool, pub samples_match_playback_rate: bool, pub countdown: CountdownType, pub countdown_offset: i32, pub bookmarks: Vec<i32>, pub distance_spacing: f64, pub beat_divisor: i32, pub grid_size: i32, pub timeline_zoom: f64, pub title: String, pub title_unicode: String, pub artist: String, pub artist_unicode: String, pub creator: String, pub version: String, pub source: String, pub tags: String, pub beatmap_id: i32, pub beatmap_set_id: i32, pub hp_drain_rate: f32, pub circle_size: f32, pub overall_difficulty: f32, pub approach_rate: f32, pub slider_multiplier: f64, pub slider_tick_rate: f64, pub background_file: String, pub breaks: Vec<BreakPeriod>, pub control_points: ControlPoints, pub custom_combo_colors: Vec<Color>, pub custom_colors: Vec<CustomColor>, pub hit_objects: Vec<HitObject>,
}
Expand description

Fully parsed content of a .osu file.

Fields§

§format_version: i32§audio_file: String§audio_lead_in: f64§preview_time: i32§default_sample_bank: SampleBank§default_sample_volume: i32§stack_leniency: f32§mode: GameMode§letterbox_in_breaks: bool§special_style: bool§widescreen_storyboard: bool§epilepsy_warning: bool§samples_match_playback_rate: bool§countdown: CountdownType§countdown_offset: i32§bookmarks: Vec<i32>§distance_spacing: f64§beat_divisor: i32§grid_size: i32§timeline_zoom: f64§title: String§title_unicode: String§artist: String§artist_unicode: String§creator: String§version: String§source: String§tags: String§beatmap_id: i32§beatmap_set_id: i32§hp_drain_rate: f32§circle_size: f32§overall_difficulty: f32§approach_rate: f32§slider_multiplier: f64§slider_tick_rate: f64§background_file: String§breaks: Vec<BreakPeriod>§control_points: ControlPoints§custom_combo_colors: Vec<Color>§custom_colors: Vec<CustomColor>§hit_objects: Vec<HitObject>

Implementations§

source§

impl Beatmap

source

pub fn from_path(path: impl AsRef<Path>) -> Result<Self, Error>

Parse a Beatmap by providing a path to a .osu file.

§Example
let path = "/path/to/file.osu";
let map: Beatmap = Beatmap::from_path(path)?;
source

pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error>

Parse a Beatmap by providing the content of a .osu file as a slice of bytes.

§Example
use rosu_map::section::general::GameMode;

let bytes: &[u8] = b"[General]
Mode: 2

[Metadata]
Creator: pishifat";

let map: Beatmap = Beatmap::from_bytes(bytes)?;
assert_eq!(map.mode, GameMode::Catch);
assert_eq!(map.creator, "pishifat");
source§

impl Beatmap

source

pub fn encode_to_path<P: AsRef<Path>>(&mut self, path: P) -> IoResult<()>

Encode a Beatmap into content of a .osu file and store it at the given path.

§Example
let mut map: Beatmap = /* ... */
let path = "./maps/123456.osu";
map.encode_to_path(path)?;
source

pub fn encode_to_string(&mut self) -> IoResult<String>

Encode a Beatmap into content of a .osu file and store it into a String.

§Example
let mut map: Beatmap = /* ... */
let content: String = map.encode_to_string()?;
source

pub fn encode<W: Write>(&mut self, writer: W) -> IoResult<()>

Encode a Beatmap into content of a .osu file.

§Example

In case of writing directly to a file, it is recommended to pass the file wrapped in a BufWriter or just use encode_to_path.

use std::{fs::File, io::BufWriter};

let mut map: Beatmap = /* ... */
let path = "./maps/123456.osu";
let file = File::create(path)?;
let writer = BufWriter::new(file);

map.encode(writer)?;

Encoding into a Vec<u8> can be done by passing a mutable reference.

let mut map: Beatmap = /* ... */
let mut bytes: Vec<u8> = Vec::with_capacity(2048);

map.encode(&mut bytes)?;

// Or just use `Beatmap::encode_to_string`
let content = String::from_utf8(bytes)?;

Trait Implementations§

source§

impl Clone for Beatmap

source§

fn clone(&self) -> Beatmap

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Beatmap

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl DecodeBeatmap for Beatmap

§

type Error = ParseBeatmapError

Error type in case something goes wrong while parsing. Read more
§

type State = BeatmapState

The parsing state which will be updated on each line and turned into Self at the end.
source§

fn parse_general(state: &mut Self::State, line: &str) -> Result<(), Self::Error>

Update the state based on a line of the [General] section.
source§

fn parse_editor(state: &mut Self::State, line: &str) -> Result<(), Self::Error>

Update the state based on a line of the [Editor] section.
source§

fn parse_metadata( state: &mut Self::State, line: &str ) -> Result<(), Self::Error>

Update the state based on a line of the [Metadata] section.
source§

fn parse_difficulty( state: &mut Self::State, line: &str ) -> Result<(), Self::Error>

Update the state based on a line of the [Difficulty] section.
source§

fn parse_events(state: &mut Self::State, line: &str) -> Result<(), Self::Error>

Update the state based on a line of the [Events] section.
source§

fn parse_timing_points( state: &mut Self::State, line: &str ) -> Result<(), Self::Error>

Update the state based on a line of the [TimingPoints] section.
source§

fn parse_colors(state: &mut Self::State, line: &str) -> Result<(), Self::Error>

Update the state based on a line of the [Colours] section.
source§

fn parse_hit_objects( state: &mut Self::State, line: &str ) -> Result<(), Self::Error>

Update the state based on a line of the [HitObjects] section.
source§

fn parse_variables(_: &mut Self::State, _: &str) -> Result<(), Self::Error>

Update the state based on a line of the [Variables] section.
source§

fn parse_catch_the_beat(_: &mut Self::State, _: &str) -> Result<(), Self::Error>

Update the state based on a line of the [CatchTheBeat] section.
source§

fn parse_mania(_: &mut Self::State, _: &str) -> Result<(), Self::Error>

Update the state based on a line of the [Mania] section.
source§

fn decode<R: BufRead>(src: R) -> Result<Self, Error>

The key method to read and parse content of a .osu file into Self. Read more
source§

fn should_skip_line(line: &str) -> bool

Whether a line should not be forwarded to the parsing methods.
source§

impl Default for Beatmap

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl From<BeatmapState> for Beatmap

source§

fn from(state: BeatmapState) -> Self

Converts to this type from the input type.
source§

impl From<Colors> for Beatmap

source§

fn from(colors: Colors) -> Self

Converts to this type from the input type.
source§

impl From<Difficulty> for Beatmap

source§

fn from(difficulty: Difficulty) -> Self

Converts to this type from the input type.
source§

impl From<Editor> for Beatmap

source§

fn from(editor: Editor) -> Self

Converts to this type from the input type.
source§

impl From<Events> for Beatmap

source§

fn from(events: Events) -> Self

Converts to this type from the input type.
source§

impl From<General> for Beatmap

source§

fn from(general: General) -> Self

Converts to this type from the input type.
source§

impl From<HitObjects> for Beatmap

source§

fn from(hit_objects: HitObjects) -> Self

Converts to this type from the input type.
source§

impl From<Metadata> for Beatmap

source§

fn from(metadata: Metadata) -> Self

Converts to this type from the input type.
source§

impl From<TimingPoints> for Beatmap

source§

fn from(timing_points: TimingPoints) -> Self

Converts to this type from the input type.
source§

impl FromStr for Beatmap

source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parse a Beatmap by providing the content of a .osu file as a string.

§Example
let s: &str = "[Difficulty]
SliderMultiplier: 3

[Editor]
BeatDivisor: 4";

let map: Beatmap = s.parse()?; // same as `Beatmap::from_str(s)`
assert_eq!(map.slider_multiplier, 3.0);
assert_eq!(map.beat_divisor, 4);
§

type Err = Error

The associated error which can be returned from parsing.
source§

impl PartialEq for Beatmap

source§

fn eq(&self, other: &Beatmap) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for Beatmap

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.