Skip to content

Commit e2c8470

Browse files
committed
My module aliases were bad
Signed-off-by: itowlson <[email protected]>
1 parent 9b9d750 commit e2c8470

File tree

1 file changed

+60
-50
lines changed

1 file changed

+60
-50
lines changed

crates/factor-blobstore/src/host.rs

+60-50
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,14 @@ use anyhow::{Context, Result};
22
use spin_core::wasmtime::component::ResourceTable;
33
use spin_core::{async_trait, wasmtime::component::Resource};
44
use spin_resource_table::Table;
5-
use spin_world::wasi::blobstore;
5+
use spin_world::wasi::blobstore::{self as bs};
66
use std::{collections::HashSet, sync::Arc};
77
use tokio::io::{ReadHalf, SimplexStream, WriteHalf};
88
use tokio::sync::mpsc;
99
use tokio::sync::RwLock;
1010
use wasmtime_wasi::WasiView;
1111

12-
use blobstore::blobstore::{self as wb};
13-
use blobstore::container::{self as wbc};
14-
use blobstore::types::{self as wbt};
15-
16-
pub use wbt::Error;
12+
pub use bs::types::Error;
1713

1814
#[async_trait]
1915
pub trait ContainerManager: Sync + Send {
@@ -33,12 +29,12 @@ pub trait ContainerManager: Sync + Send {
3329
pub trait Container: Sync + Send {
3430
async fn exists(&self) -> anyhow::Result<bool>;
3531
async fn name(&self) -> String;
36-
async fn info(&self) -> anyhow::Result<wbt::ContainerMetadata>;
32+
async fn info(&self) -> anyhow::Result<bs::types::ContainerMetadata>;
3733
async fn clear(&self) -> anyhow::Result<()>;
3834
async fn delete_object(&self, name: &str) -> anyhow::Result<()>;
3935
async fn delete_objects(&self, names: &[String]) -> anyhow::Result<()>;
4036
async fn has_object(&self, name: &str) -> anyhow::Result<bool>;
41-
async fn object_info(&self, name: &str) -> anyhow::Result<wbt::ObjectMetadata>;
37+
async fn object_info(&self, name: &str) -> anyhow::Result<bs::types::ObjectMetadata>;
4238
async fn get_data(
4339
&self,
4440
name: &str,
@@ -176,7 +172,7 @@ impl<'a> BlobStoreDispatch<'a> {
176172

177173
pub async fn get_container(
178174
&self,
179-
container: Resource<wb::Container>,
175+
container: Resource<bs::blobstore::Container>,
180176
) -> anyhow::Result<Arc<dyn Container>> {
181177
self.containers
182178
.read()
@@ -192,7 +188,7 @@ impl<'a> BlobStoreDispatch<'a> {
192188

193189
async fn take_incoming_value(
194190
&mut self,
195-
resource: Resource<wbc::IncomingValue>,
191+
resource: Resource<bs::container::IncomingValue>,
196192
) -> Result<Box<dyn IncomingData>, String> {
197193
self.incoming_values
198194
.write()
@@ -202,15 +198,18 @@ impl<'a> BlobStoreDispatch<'a> {
202198
}
203199
}
204200

205-
impl wb::Host for BlobStoreDispatch<'_> {
201+
impl bs::blobstore::Host for BlobStoreDispatch<'_> {
206202
async fn create_container(
207203
&mut self,
208204
_name: String,
209-
) -> Result<Resource<wbc::Container>, String> {
205+
) -> Result<Resource<bs::container::Container>, String> {
210206
Err("This version of Spin does not support creating containers".to_owned())
211207
}
212208

213-
async fn get_container(&mut self, name: String) -> Result<Resource<wbc::Container>, String> {
209+
async fn get_container(
210+
&mut self,
211+
name: String,
212+
) -> Result<Resource<bs::container::Container>, String> {
214213
if self.allowed_containers.contains(&name) {
215214
let container = self.manager.get(&name).await?;
216215
let rep = self.containers.write().await.push(container).unwrap();
@@ -233,25 +232,33 @@ impl wb::Host for BlobStoreDispatch<'_> {
233232
}
234233
}
235234

236-
async fn copy_object(&mut self, _src: wb::ObjectId, _dest: wb::ObjectId) -> Result<(), String> {
235+
async fn copy_object(
236+
&mut self,
237+
_src: bs::blobstore::ObjectId,
238+
_dest: bs::blobstore::ObjectId,
239+
) -> Result<(), String> {
237240
Err("This version of Spin does not support copying objects".to_owned())
238241
}
239242

240-
async fn move_object(&mut self, _src: wb::ObjectId, _dest: wb::ObjectId) -> Result<(), String> {
243+
async fn move_object(
244+
&mut self,
245+
_src: bs::blobstore::ObjectId,
246+
_dest: bs::blobstore::ObjectId,
247+
) -> Result<(), String> {
241248
Err("This version of Spin does not support moving objects".to_owned())
242249
}
243250
}
244251

245-
impl wbt::Host for BlobStoreDispatch<'_> {
252+
impl bs::types::Host for BlobStoreDispatch<'_> {
246253
fn convert_error(&mut self, error: String) -> anyhow::Result<String> {
247254
Ok(error)
248255
}
249256
}
250257

251-
impl wbt::HostIncomingValue for BlobStoreDispatch<'_> {
258+
impl bs::types::HostIncomingValue for BlobStoreDispatch<'_> {
252259
async fn incoming_value_consume_sync(
253260
&mut self,
254-
self_: Resource<wbt::IncomingValue>,
261+
self_: Resource<bs::types::IncomingValue>,
255262
) -> Result<Vec<u8>, String> {
256263
let mut incoming = self.take_incoming_value(self_).await?;
257264
incoming
@@ -263,7 +270,7 @@ impl wbt::HostIncomingValue for BlobStoreDispatch<'_> {
263270

264271
async fn incoming_value_consume_async(
265272
&mut self,
266-
self_: Resource<wbt::IncomingValue>,
273+
self_: Resource<bs::types::IncomingValue>,
267274
) -> Result<Resource<wasmtime_wasi::InputStream>, String> {
268275
let mut incoming = self.take_incoming_value(self_).await?;
269276
let async_body = incoming.as_mut().consume_async();
@@ -272,22 +279,22 @@ impl wbt::HostIncomingValue for BlobStoreDispatch<'_> {
272279
Ok(resource)
273280
}
274281

275-
async fn size(&mut self, self_: Resource<wbt::IncomingValue>) -> anyhow::Result<u64> {
282+
async fn size(&mut self, self_: Resource<bs::types::IncomingValue>) -> anyhow::Result<u64> {
276283
let mut lock = self.incoming_values.write().await;
277284
let incoming = lock
278285
.get_mut(self_.rep())
279286
.ok_or_else(|| anyhow::anyhow!("invalid incoming-value resource"))?;
280287
incoming.size().await
281288
}
282289

283-
async fn drop(&mut self, rep: Resource<wbt::IncomingValue>) -> anyhow::Result<()> {
290+
async fn drop(&mut self, rep: Resource<bs::types::IncomingValue>) -> anyhow::Result<()> {
284291
self.incoming_values.write().await.remove(rep.rep());
285292
Ok(())
286293
}
287294
}
288295

289-
impl wbt::HostOutgoingValue for BlobStoreDispatch<'_> {
290-
async fn new_outgoing_value(&mut self) -> anyhow::Result<Resource<wbt::OutgoingValue>> {
296+
impl bs::types::HostOutgoingValue for BlobStoreDispatch<'_> {
297+
async fn new_outgoing_value(&mut self) -> anyhow::Result<Resource<bs::types::OutgoingValue>> {
291298
let outgoing_value = OutgoingValue::new();
292299
let rep = self
293300
.outgoing_values
@@ -300,7 +307,7 @@ impl wbt::HostOutgoingValue for BlobStoreDispatch<'_> {
300307

301308
async fn outgoing_value_write_body(
302309
&mut self,
303-
self_: Resource<wbt::OutgoingValue>,
310+
self_: Resource<bs::types::OutgoingValue>,
304311
) -> anyhow::Result<Result<Resource<wasmtime_wasi::OutputStream>, ()>> {
305312
let mut lock = self.outgoing_values.write().await;
306313
let outgoing = lock
@@ -314,7 +321,7 @@ impl wbt::HostOutgoingValue for BlobStoreDispatch<'_> {
314321
Ok(Ok(resource))
315322
}
316323

317-
async fn finish(&mut self, self_: Resource<wbt::OutgoingValue>) -> Result<(), String> {
324+
async fn finish(&mut self, self_: Resource<bs::types::OutgoingValue>) -> Result<(), String> {
318325
let mut lock = self.outgoing_values.write().await;
319326
let outgoing = lock
320327
.get_mut(self_.rep())
@@ -333,17 +340,17 @@ impl wbt::HostOutgoingValue for BlobStoreDispatch<'_> {
333340
}
334341
}
335342

336-
async fn drop(&mut self, rep: Resource<wbt::OutgoingValue>) -> anyhow::Result<()> {
343+
async fn drop(&mut self, rep: Resource<bs::types::OutgoingValue>) -> anyhow::Result<()> {
337344
self.outgoing_values.write().await.remove(rep.rep());
338345
Ok(())
339346
}
340347
}
341348

342349
// TODO: TBD if these belong on BSD or some other struct (like the one that maps to a Container resource JUST SAYIN)
343-
impl wbc::Host for BlobStoreDispatch<'_> {}
350+
impl bs::container::Host for BlobStoreDispatch<'_> {}
344351

345-
impl wbc::HostContainer for BlobStoreDispatch<'_> {
346-
async fn name(&mut self, self_: Resource<wbc::Container>) -> Result<String, String> {
352+
impl bs::container::HostContainer for BlobStoreDispatch<'_> {
353+
async fn name(&mut self, self_: Resource<bs::container::Container>) -> Result<String, String> {
347354
let lock = self.containers.read().await;
348355
let container = lock
349356
.get(self_.rep())
@@ -353,8 +360,8 @@ impl wbc::HostContainer for BlobStoreDispatch<'_> {
353360

354361
async fn info(
355362
&mut self,
356-
self_: Resource<wbc::Container>,
357-
) -> Result<wbc::ContainerMetadata, String> {
363+
self_: Resource<bs::container::Container>,
364+
) -> Result<bs::container::ContainerMetadata, String> {
358365
let lock = self.containers.read().await;
359366
let container = lock
360367
.get(self_.rep())
@@ -364,11 +371,11 @@ impl wbc::HostContainer for BlobStoreDispatch<'_> {
364371

365372
async fn get_data(
366373
&mut self,
367-
self_: Resource<wbc::Container>,
368-
name: wbc::ObjectName,
374+
self_: Resource<bs::container::Container>,
375+
name: bs::container::ObjectName,
369376
start: u64,
370377
end: u64,
371-
) -> Result<Resource<wbt::IncomingValue>, String> {
378+
) -> Result<Resource<bs::types::IncomingValue>, String> {
372379
let lock = self.containers.read().await;
373380
let container = lock
374381
.get(self_.rep())
@@ -383,9 +390,9 @@ impl wbc::HostContainer for BlobStoreDispatch<'_> {
383390

384391
async fn write_data(
385392
&mut self,
386-
self_: Resource<wbc::Container>,
387-
name: wbc::ObjectName,
388-
data: Resource<wbt::OutgoingValue>,
393+
self_: Resource<bs::container::Container>,
394+
name: bs::container::ObjectName,
395+
data: Resource<bs::types::OutgoingValue>,
389396
) -> Result<(), String> {
390397
let lock = self.containers.read().await;
391398
let container = lock
@@ -407,8 +414,8 @@ impl wbc::HostContainer for BlobStoreDispatch<'_> {
407414

408415
async fn list_objects(
409416
&mut self,
410-
self_: Resource<wbc::Container>,
411-
) -> Result<Resource<wbc::StreamObjectNames>, String> {
417+
self_: Resource<bs::container::Container>,
418+
) -> Result<Resource<bs::container::StreamObjectNames>, String> {
412419
let lock = self.containers.read().await;
413420
let container = lock
414421
.get(self_.rep())
@@ -420,7 +427,7 @@ impl wbc::HostContainer for BlobStoreDispatch<'_> {
420427

421428
async fn delete_object(
422429
&mut self,
423-
self_: Resource<wbc::Container>,
430+
self_: Resource<bs::container::Container>,
424431
name: String,
425432
) -> Result<(), String> {
426433
let lock = self.containers.read().await;
@@ -435,7 +442,7 @@ impl wbc::HostContainer for BlobStoreDispatch<'_> {
435442

436443
async fn delete_objects(
437444
&mut self,
438-
self_: Resource<wbc::Container>,
445+
self_: Resource<bs::container::Container>,
439446
names: Vec<String>,
440447
) -> Result<(), String> {
441448
let lock = self.containers.read().await;
@@ -450,7 +457,7 @@ impl wbc::HostContainer for BlobStoreDispatch<'_> {
450457

451458
async fn has_object(
452459
&mut self,
453-
self_: Resource<wbc::Container>,
460+
self_: Resource<bs::container::Container>,
454461
name: String,
455462
) -> Result<bool, String> {
456463
let lock = self.containers.read().await;
@@ -462,9 +469,9 @@ impl wbc::HostContainer for BlobStoreDispatch<'_> {
462469

463470
async fn object_info(
464471
&mut self,
465-
self_: Resource<wbc::Container>,
472+
self_: Resource<bs::container::Container>,
466473
name: String,
467-
) -> Result<wbt::ObjectMetadata, String> {
474+
) -> Result<bs::types::ObjectMetadata, String> {
468475
let lock = self.containers.read().await;
469476
let container = lock
470477
.get(self_.rep())
@@ -475,24 +482,24 @@ impl wbc::HostContainer for BlobStoreDispatch<'_> {
475482
.map_err(|e| e.to_string())
476483
}
477484

478-
async fn clear(&mut self, self_: Resource<wbc::Container>) -> Result<(), String> {
485+
async fn clear(&mut self, self_: Resource<bs::container::Container>) -> Result<(), String> {
479486
let lock = self.containers.read().await;
480487
let container = lock
481488
.get(self_.rep())
482489
.ok_or_else(|| "invalid container resource".to_string())?;
483490
container.clear().await.map_err(|e| e.to_string())
484491
}
485492

486-
async fn drop(&mut self, rep: Resource<wbc::Container>) -> anyhow::Result<()> {
493+
async fn drop(&mut self, rep: Resource<bs::container::Container>) -> anyhow::Result<()> {
487494
self.containers.write().await.remove(rep.rep());
488495
Ok(())
489496
}
490497
}
491498

492-
impl wbc::HostStreamObjectNames for BlobStoreDispatch<'_> {
499+
impl bs::container::HostStreamObjectNames for BlobStoreDispatch<'_> {
493500
async fn read_stream_object_names(
494501
&mut self,
495-
self_: Resource<wbc::StreamObjectNames>,
502+
self_: Resource<bs::container::StreamObjectNames>,
496503
len: u64,
497504
) -> Result<(Vec<String>, bool), String> {
498505
let mut lock = self.object_names.write().await;
@@ -504,7 +511,7 @@ impl wbc::HostStreamObjectNames for BlobStoreDispatch<'_> {
504511

505512
async fn skip_stream_object_names(
506513
&mut self,
507-
self_: Resource<wbc::StreamObjectNames>,
514+
self_: Resource<bs::container::StreamObjectNames>,
508515
num: u64,
509516
) -> Result<(u64, bool), String> {
510517
let mut lock = self.object_names.write().await;
@@ -514,7 +521,10 @@ impl wbc::HostStreamObjectNames for BlobStoreDispatch<'_> {
514521
object_names.skip(num).await.map_err(|e| e.to_string())
515522
}
516523

517-
async fn drop(&mut self, rep: Resource<wbc::StreamObjectNames>) -> anyhow::Result<()> {
524+
async fn drop(
525+
&mut self,
526+
rep: Resource<bs::container::StreamObjectNames>,
527+
) -> anyhow::Result<()> {
518528
self.object_names.write().await.remove(rep.rep());
519529
Ok(())
520530
}

0 commit comments

Comments
 (0)