From b2abae477115dc6ca97a767c6800c7c3f1aa0ebb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 25 Sep 2023 00:07:22 +0200 Subject: refactor: rewrite more ops to op2 (#20666) --- ext/fs/ops.rs | 91 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 46 insertions(+), 45 deletions(-) (limited to 'ext/fs/ops.rs') diff --git a/ext/fs/ops.rs b/ext/fs/ops.rs index 289c3de72..bc09a4a25 100644 --- a/ext/fs/ops.rs +++ b/ext/fs/ops.rs @@ -11,7 +11,6 @@ use std::rc::Rc; use deno_core::error::custom_error; use deno_core::error::type_error; use deno_core::error::AnyError; -use deno_core::op; use deno_core::op2; use deno_core::CancelFuture; use deno_core::CancelHandle; @@ -767,11 +766,11 @@ where Ok(target_string) } -#[op] +#[op2(fast)] pub fn op_fs_truncate_sync

( state: &mut OpState, - path: &str, - len: u64, + #[string] path: &str, + #[number] len: u64, ) -> Result<(), AnyError> where P: FsPermissions + 'static, @@ -789,11 +788,11 @@ where Ok(()) } -#[op] +#[op2(async)] pub async fn op_fs_truncate_async

( state: Rc>, - path: String, - len: u64, + #[string] path: String, + #[number] len: u64, ) -> Result<(), AnyError> where P: FsPermissions + 'static, @@ -815,14 +814,14 @@ where Ok(()) } -#[op] +#[op2(fast)] pub fn op_fs_utime_sync

( state: &mut OpState, - path: &str, - atime_secs: i64, - atime_nanos: u32, - mtime_secs: i64, - mtime_nanos: u32, + #[string] path: &str, + #[number] atime_secs: i64, + #[smi] atime_nanos: u32, + #[number] mtime_secs: i64, + #[smi] mtime_nanos: u32, ) -> Result<(), AnyError> where P: FsPermissions + 'static, @@ -838,14 +837,14 @@ where Ok(()) } -#[op] +#[op2(async)] pub async fn op_fs_utime_async

( state: Rc>, - path: String, - atime_secs: i64, - atime_nanos: u32, - mtime_secs: i64, - mtime_nanos: u32, + #[string] path: String, + #[number] atime_secs: i64, + #[smi] atime_nanos: u32, + #[number] mtime_secs: i64, + #[smi] mtime_nanos: u32, ) -> Result<(), AnyError> where P: FsPermissions + 'static, @@ -1313,12 +1312,13 @@ fn to_seek_from(offset: i64, whence: i32) -> Result { Ok(seek_from) } -#[op] +#[op2(fast)] +#[number] pub fn op_fs_seek_sync( state: &mut OpState, - rid: ResourceId, - offset: i64, - whence: i32, + #[smi] rid: ResourceId, + #[number] offset: i64, + #[smi] whence: i32, ) -> Result { let pos = to_seek_from(offset, whence)?; let file = FileResource::get_file(state, rid)?; @@ -1326,12 +1326,13 @@ pub fn op_fs_seek_sync( Ok(cursor) } -#[op] +#[op2(async)] +#[number] pub async fn op_fs_seek_async( state: Rc>, - rid: ResourceId, - offset: i64, - whence: i32, + #[smi] rid: ResourceId, + #[number] offset: i64, + #[smi] whence: i32, ) -> Result { let pos = to_seek_from(offset, whence)?; let file = FileResource::get_file(&state.borrow(), rid)?; @@ -1449,50 +1450,50 @@ pub async fn op_fs_funlock_async( Ok(()) } -#[op] +#[op2(fast)] pub fn op_fs_ftruncate_sync( state: &mut OpState, - rid: ResourceId, - len: u64, + #[smi] rid: ResourceId, + #[number] len: u64, ) -> Result<(), AnyError> { let file = FileResource::get_file(state, rid)?; file.truncate_sync(len)?; Ok(()) } -#[op] +#[op2(async)] pub async fn op_fs_ftruncate_async( state: Rc>, - rid: ResourceId, - len: u64, + #[smi] rid: ResourceId, + #[number] len: u64, ) -> Result<(), AnyError> { let file = FileResource::get_file(&state.borrow(), rid)?; file.truncate_async(len).await?; Ok(()) } -#[op] +#[op2(fast)] pub fn op_fs_futime_sync( state: &mut OpState, - rid: ResourceId, - atime_secs: i64, - atime_nanos: u32, - mtime_secs: i64, - mtime_nanos: u32, + #[smi] rid: ResourceId, + #[number] atime_secs: i64, + #[smi] atime_nanos: u32, + #[number] mtime_secs: i64, + #[smi] mtime_nanos: u32, ) -> Result<(), AnyError> { let file = FileResource::get_file(state, rid)?; file.utime_sync(atime_secs, atime_nanos, mtime_secs, mtime_nanos)?; Ok(()) } -#[op] +#[op2(async)] pub async fn op_fs_futime_async( state: Rc>, - rid: ResourceId, - atime_secs: i64, - atime_nanos: u32, - mtime_secs: i64, - mtime_nanos: u32, + #[smi] rid: ResourceId, + #[number] atime_secs: i64, + #[smi] atime_nanos: u32, + #[number] mtime_secs: i64, + #[smi] mtime_nanos: u32, ) -> Result<(), AnyError> { let file = FileResource::get_file(&state.borrow(), rid)?; file -- cgit v1.2.3