Function bevy::asset::ron::de::from_bytes

source ยท
pub fn from_bytes<'a, T>(s: &'a [u8]) -> Result<T, SpannedError>
where T: Deserialize<'a>,
Expand description

A convenience function for building a deserializer and deserializing a value of type T from bytes.

Examples found in repository?
examples/asset/custom_asset.rs (line 44)
36
37
38
39
40
41
42
43
44
45
46
    async fn load<'a>(
        &'a self,
        reader: &'a mut Reader<'_>,
        _settings: &'a (),
        _load_context: &'a mut LoadContext<'_>,
    ) -> Result<Self::Asset, Self::Error> {
        let mut bytes = Vec::new();
        reader.read_to_end(&mut bytes).await?;
        let custom_asset = ron::de::from_bytes::<CustomAsset>(&bytes)?;
        Ok(custom_asset)
    }
More examples
Hide additional examples
examples/asset/processing/asset_processing.rs (line 145)
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
    async fn load<'a>(
        &'a self,
        reader: &'a mut Reader<'_>,
        _settings: &'a Self::Settings,
        load_context: &'a mut LoadContext<'_>,
    ) -> Result<CoolText, Self::Error> {
        let mut bytes = Vec::new();
        reader.read_to_end(&mut bytes).await?;
        let ron: CoolTextRon = ron::de::from_bytes(&bytes)?;
        let mut base_text = ron.text;
        for embedded in ron.embedded_dependencies {
            let loaded = load_context.load_direct(&embedded).await?;
            let text = loaded.get::<Text>().unwrap();
            base_text.push_str(&text.0);
        }
        Ok(CoolText {
            text: base_text,
            dependencies: ron
                .dependencies
                .iter()
                .map(|p| load_context.load(p))
                .collect(),
        })
    }