Skip to content

Commit 8c5977d

Browse files
committed
Write release notes and migration guides.
1 parent 0409603 commit 8c5977d

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: The `AssetReader` trait now takes a `ReaderRequiredFeatures` argument.
3+
pull_requests: []
4+
---
5+
6+
The `AssetReader::read` method now takes an additional `ReaderRequiredFeatures` argument. If
7+
previously you had:
8+
9+
```rust
10+
struct MyAssetReader;
11+
12+
impl AssetReader for MyAssetReader {
13+
async fn read<'a>(
14+
&'a self,
15+
path: &'a Path,
16+
) -> Result<impl Reader + 'a, AssetReaderError> {
17+
todo!()
18+
}
19+
20+
// more stuff...
21+
}
22+
```
23+
24+
Change this to:
25+
26+
```rust
27+
struct MyAssetReader;
28+
29+
impl AssetReader for MyAssetReader {
30+
async fn read<'a>(
31+
&'a self,
32+
path: &'a Path,
33+
_required_features: ReaderRequiredFeatures,
34+
) -> Result<impl Reader + 'a, AssetReaderError> {
35+
todo!()
36+
}
37+
38+
// more stuff...
39+
}
40+
```
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: Implementations of `Reader` now must implement `AsyncSeek`, and `AsyncSeekForward` is deleted.
3+
pull_requests: []
4+
---
5+
6+
The `Reader` trait no longer requires implementing `AsyncSeekForward` and instead requires
7+
implementing `AsyncSeek`. Each reader will have its own unique implementation so implementing this
8+
will be case specific. The simplest implementation is to simply reject these seeking cases like so:
9+
10+
```rust
11+
impl AsyncSeek for MyReader {
12+
fn poll_seek(
13+
self: Pin<&mut Self>,
14+
_cx: &mut core::task::Context<'_>,
15+
pos: SeekFrom,
16+
) -> Poll<std::io::Result<u64>> {
17+
let forward = match pos {
18+
SeekFrom::Current(curr) if curr >= 0 => curr as u64,
19+
_ => return std::io::Error::new(
20+
std::io::ErrorKind::InvalidInput,
21+
"invalid seek mode",
22+
),
23+
};
24+
25+
// Do whatever your previous `AsyncSeekForward` implementation did...
26+
}
27+
}
28+
```
29+
30+
In addition, the `AssetReader` trait now includes a `ReaderRequiredFeatures` argument which can be
31+
used to return an error early for invalid requests. For example:
32+
33+
```rust
34+
impl AssetReader for MyAssetReader {
35+
async fn read<'a>(
36+
&'a self,
37+
path: &'a Path,
38+
required_features: ReaderRequiredFeatures,
39+
) -> Result<impl Reader, AssetReaderError> {
40+
match required_features.seek {
41+
SeekKind::Forward => {}
42+
SeekKind::AnySeek => return Err(UnsupportedReaderFeature::AnySeek),
43+
}
44+
45+
// Do whatever your previous `AssetReader` implementation did, like...
46+
Ok(MyReader)
47+
}
48+
}
49+
```
50+
51+
Since we now just use the `AsyncSeek` trait, we've deleted the `AsyncSeekForward` trait. Users of
52+
this trait can migrate by calling the `AsyncSeek::poll_seek` method with
53+
`SeekFrom::Current(offset)`, or the `AsyncSeekExt::seek` method.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
title: The `AssetReader` trait can now (optionally) support seeking any direction.
3+
authors: ["@andriyDev"]
4+
pull_requests: []
5+
---
6+
7+
In Bevy 0.15, we replaced the `AsyncSeek` super trait on `Reader` with `AsyncSeekForward`. This
8+
allowed our `Reader` trait to apply to more cases (e.g., it could allow cases like an HTTP request,
9+
which may not support seeking backwards). However, it also meant that we could no longer use seeking
10+
fully where it was available.
11+
12+
To resolve this issue, we now allow `AssetLoader`s to provide a `ReaderRequiredFeatures` to the
13+
`AssetReader`. The `AssetReader` can then choose how to handle those required features. For example,
14+
it can return an error to indicate that the feature is not supported, or it can choose to use a
15+
different `Reader` implementation to fallback in order to continue to support the feature.
16+
17+
This allowed us to bring back the "requirement" the `Reader: AsyncSeek`, but with a more relaxed
18+
policy: the `Reader` may choose to avoid supporting certain features (corresponding to fields in
19+
`ReaderRequiredFeatures`).
20+
21+
Our general recommendation is that if your `Reader` implementation does not support a feature, make
22+
your `AssetReader` just return an error for that feature. Usually, an `AssetLoader` can implement a
23+
fallback itself (e.g., reading all the data into memory and then loading from that), and loaders can
24+
be selected using `.meta` files (allowing for fine-grained opt-in in these cases). However if there
25+
is some reasonable implementation you can provide (even if not optimal), feel free to provide one!

0 commit comments

Comments
 (0)