Skip to content

Commit

Permalink
Use Result<(), ErrorEnum> where applicable
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
  • Loading branch information
jschwe committed Jan 30, 2025
1 parent 884c178 commit d72b6ab
Show file tree
Hide file tree
Showing 75 changed files with 1,000 additions and 899 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ ohos-sys-opaque-types = { version = "0.1.4", path = "components/opaque-types" }


[dependencies]
arkui-sys = { version = "0.2.4", optional = true, path = "components/arkui" }
arkui-sys = { version = "0.3.0", optional = true, path = "components/arkui" }
document-features = { version = "0.2", optional = true }
hilog-sys = { version = "0.1.4", optional = true, path = "components/hilog"}
hitrace-sys = { version = "0.1.4", optional = true, path = "components/hitrace"}
ohos-deviceinfo-sys = { version = "0.1.2", optional = true, path = "components/deviceinfo"}
ohos-drawing-sys = { path = "components/drawing", version = "0.2.2", optional = true}
ohos-drawing-sys = { path = "components/drawing", version = "0.3.0", optional = true}
ohos-image-kit-sys = {version = "0.2", optional = true, path = "components/multimedia/image_framework"}
ohos-ime-sys = { version = "0.1.4", optional = true, path = "components/inputmethod"}
ohos-input-sys = { version = "0.1.1", optional = true, path = "components/multimodal-input"}
ohos-ime-sys = { version = "0.2.0", optional = true, path = "components/inputmethod"}
ohos-input-sys = { version = "0.2.0", optional = true, path = "components/multimodal-input"}
ohos-rawfile-sys = { version = "0.1.0", optional = true, path = "components/rawfile"}
ohos-sys-opaque-types = { workspace = true}
ohos-vsync-sys = { version = "0.1.2", optional = true, path = "components/vsync"}
Expand Down
10 changes: 10 additions & 0 deletions components/arkui/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Changelog

## 0.3.0 (unreleased)

### Breaking

- Removed `ARKUI_DRAG_RESULT_` prefix from `ArkUI_DragResult` variants.
- Removed `GESTURE_INTERRUPT_RESULT_` prefix from `ArkUI_GestureInterruptResult` variants.
- Replace `ArkUI_ErrorCode` with `ArkUiResult` (an alias to `Result<(), NonZero<ArkUiErrorCode>>`)

## 0.2.3 (2025-01-09)

### Add
Expand Down
4 changes: 2 additions & 2 deletions components/arkui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "arkui-sys"
version = "0.2.4"
version = "0.3.0"
edition = "2021"
description = "Bindings to the native ArkUI API of OpenHarmony"
license = "Apache-2.0"
Expand All @@ -11,7 +11,7 @@ readme = "README.md"

[dependencies]
document-features = { version = "0.2", optional = true }
ohos-drawing-sys = { version = "0.2", optional = true, path = "../drawing" }
ohos-drawing-sys = { version = "0.3", optional = true, path = "../drawing" }
ohos-sys-opaque-types = { workspace = true }

[features]
Expand Down
6 changes: 3 additions & 3 deletions components/arkui/src/drag_and_drop/drag_and_drop_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ pub use ohos_sys_opaque_types::OH_PixelmapNative;
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_DragResult {
/// The drag and drop operation succeeded.
pub const ARKUI_DRAG_RESULT_SUCCESSFUL: ArkUI_DragResult = ArkUI_DragResult(0);
pub const SUCCESSFUL: ArkUI_DragResult = ArkUI_DragResult(0);
}
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_DragResult {
/// The drag and drop operation failed.
pub const ARKUI_DRAG_RESULT_FAILED: ArkUI_DragResult = ArkUI_DragResult(1);
pub const FAILED: ArkUI_DragResult = ArkUI_DragResult(1);
}
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_DragResult {
/// The drag and drop operation was canceled.
pub const ARKUI_DRAG_RESULT_CANCELED: ArkUI_DragResult = ArkUI_DragResult(2);
pub const CANCELED: ArkUI_DragResult = ArkUI_DragResult(2);
}
#[repr(transparent)]
/// Defines an enum for drag results, which are set by the data receiver and transferred by the system to the
Expand Down
6 changes: 2 additions & 4 deletions components/arkui/src/native_gesture/native_gesture_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,13 @@ pub struct ArkUI_GestureRecognizerType(pub ::core::ffi::c_uint);
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_GestureInterruptResult {
/// The gesture recognition process continues.
pub const GESTURE_INTERRUPT_RESULT_CONTINUE: ArkUI_GestureInterruptResult =
ArkUI_GestureInterruptResult(0);
pub const CONTINUE: ArkUI_GestureInterruptResult = ArkUI_GestureInterruptResult(0);
}
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_GestureInterruptResult {
/// The gesture recognition process is paused.
pub const GESTURE_INTERRUPT_RESULT_REJECT: ArkUI_GestureInterruptResult =
ArkUI_GestureInterruptResult(1);
pub const REJECT: ArkUI_GestureInterruptResult = ArkUI_GestureInterruptResult(1);
}
#[repr(transparent)]
/// Enumerates gesture interruption results.
Expand Down
27 changes: 12 additions & 15 deletions components/arkui/src/native_node_napi/native_node_napi_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ extern "C" {
buffer: *mut ::core::ffi::c_char,
bufferSize: i32,
writeLength: *mut i32,
) -> ArkUI_ErrorCode;
) -> ArkUiResult;
/// Obtain the name of the NavDestination component where the node is located.
///
/// # Arguments
Expand Down Expand Up @@ -200,7 +200,7 @@ extern "C" {
buffer: *mut ::core::ffi::c_char,
bufferSize: i32,
writeLength: *mut i32,
) -> ArkUI_ErrorCode;
) -> ArkUiResult;
/// Based on the given index value, obtain the length of the Navigation stack where the node is located.
///
/// # Arguments
Expand All @@ -220,7 +220,7 @@ extern "C" {
/// Available since API-level: 12
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
pub fn OH_ArkUI_GetNavStackLength(node: ArkUI_NodeHandle, length: *mut i32) -> ArkUI_ErrorCode;
pub fn OH_ArkUI_GetNavStackLength(node: ArkUI_NodeHandle, length: *mut i32) -> ArkUiResult;
/// Based on the given index value, obtain the page name of the corresponding position
/// in the navigation stack where the node is located.
/// Index values are counted from 0, with 0 being the bottom of the stack.
Expand Down Expand Up @@ -260,7 +260,7 @@ extern "C" {
buffer: *mut ::core::ffi::c_char,
bufferSize: i32,
writeLength: *mut i32,
) -> ArkUI_ErrorCode;
) -> ArkUiResult;
/// Obtain the ID of the NavDestination component where the node is located.
///
/// # Arguments
Expand Down Expand Up @@ -294,7 +294,7 @@ extern "C" {
buffer: *mut ::core::ffi::c_char,
bufferSize: i32,
writeLength: *mut i32,
) -> ArkUI_ErrorCode;
) -> ArkUiResult;
/// Obtain the state of the NavDestination component where the node is located.
///
/// # Arguments
Expand All @@ -317,7 +317,7 @@ extern "C" {
pub fn OH_ArkUI_GetNavDestinationState(
node: ArkUI_NodeHandle,
state: *mut ArkUI_NavDestinationState,
) -> ArkUI_ErrorCode;
) -> ArkUiResult;
/// Obtain the index of the NavDestination component on the Navigation stack where the node is located.
///
/// # Arguments
Expand All @@ -337,10 +337,7 @@ extern "C" {
/// Available since API-level: 12
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
pub fn OH_ArkUI_GetNavDestinationIndex(
node: ArkUI_NodeHandle,
index: *mut i32,
) -> ArkUI_ErrorCode;
pub fn OH_ArkUI_GetNavDestinationIndex(node: ArkUI_NodeHandle, index: *mut i32) -> ArkUiResult;
/// Obtain the parameters of the NavDestination component where the node is located.
///
/// # Arguments
Expand Down Expand Up @@ -375,7 +372,7 @@ extern "C" {
/// Available since API-level: 12
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
pub fn OH_ArkUI_GetRouterPageIndex(node: ArkUI_NodeHandle, index: *mut i32) -> ArkUI_ErrorCode;
pub fn OH_ArkUI_GetRouterPageIndex(node: ArkUI_NodeHandle, index: *mut i32) -> ArkUiResult;
/// Obtain the name of the page where the node is located.
///
/// # Arguments
Expand Down Expand Up @@ -409,7 +406,7 @@ extern "C" {
buffer: *mut ::core::ffi::c_char,
bufferSize: i32,
writeLength: *mut i32,
) -> ArkUI_ErrorCode;
) -> ArkUiResult;
/// Obtain the path of the page where the node is located.
///
/// # Arguments
Expand Down Expand Up @@ -443,7 +440,7 @@ extern "C" {
buffer: *mut ::core::ffi::c_char,
bufferSize: i32,
writeLength: *mut i32,
) -> ArkUI_ErrorCode;
) -> ArkUiResult;
/// Obtain the state of the page where the node is located.
///
/// # Arguments
Expand All @@ -466,7 +463,7 @@ extern "C" {
pub fn OH_ArkUI_GetRouterPageState(
node: ArkUI_NodeHandle,
state: *mut ArkUI_RouterPageState,
) -> ArkUI_ErrorCode;
) -> ArkUiResult;
/// Obtain the ID of the page where the node is located.
///
/// # Arguments
Expand Down Expand Up @@ -500,5 +497,5 @@ extern "C" {
buffer: *mut ::core::ffi::c_char,
bufferSize: i32,
writeLength: *mut i32,
) -> ArkUI_ErrorCode;
) -> ArkUiResult;
}
86 changes: 47 additions & 39 deletions components/arkui/src/native_type/native_type_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3608,106 +3608,114 @@ impl ArkUI_ListItemSwipeEdgeEffect {
pub struct ArkUI_ListItemSwipeEdgeEffect(pub ::core::ffi::c_uint);
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_ErrorCode {
/// No errors.
pub const ARKUI_ERROR_CODE_NO_ERROR: ArkUI_ErrorCode = ArkUI_ErrorCode(0);
}
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_ErrorCode {
impl ArkUiErrorCode {
/// Parameter error.
pub const ARKUI_ERROR_CODE_PARAM_INVALID: ArkUI_ErrorCode = ArkUI_ErrorCode(401);
pub const PARAM_INVALID: ArkUiErrorCode =
ArkUiErrorCode(const { core::num::NonZero::new(401).unwrap() });
}
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_ErrorCode {
impl ArkUiErrorCode {
/// The component does not support specific properties or events.
pub const ARKUI_ERROR_CODE_ATTRIBUTE_OR_EVENT_NOT_SUPPORTED: ArkUI_ErrorCode =
ArkUI_ErrorCode(106102);
pub const ATTRIBUTE_OR_EVENT_NOT_SUPPORTED: ArkUiErrorCode =
ArkUiErrorCode(const { core::num::NonZero::new(106102).unwrap() });
}
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_ErrorCode {
impl ArkUiErrorCode {
/// The corresponding operation does not support nodes created by ArkTS.
pub const ARKUI_ERROR_CODE_ARKTS_NODE_NOT_SUPPORTED: ArkUI_ErrorCode = ArkUI_ErrorCode(106103);
pub const ARKTS_NODE_NOT_SUPPORTED: ArkUiErrorCode =
ArkUiErrorCode(const { core::num::NonZero::new(106103).unwrap() });
}
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_ErrorCode {
impl ArkUiErrorCode {
/// The lazy loading adapter is not bound to the component.
pub const ARKUI_ERROR_CODE_ADAPTER_NOT_BOUND: ArkUI_ErrorCode = ArkUI_ErrorCode(106104);
pub const ADAPTER_NOT_BOUND: ArkUiErrorCode =
ArkUiErrorCode(const { core::num::NonZero::new(106104).unwrap() });
}
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_ErrorCode {
impl ArkUiErrorCode {
/// The adapter already exists.
pub const ARKUI_ERROR_CODE_ADAPTER_EXIST: ArkUI_ErrorCode = ArkUI_ErrorCode(106105);
pub const ADAPTER_EXIST: ArkUiErrorCode =
ArkUiErrorCode(const { core::num::NonZero::new(106105).unwrap() });
}
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_ErrorCode {
impl ArkUiErrorCode {
/// The corresponding node already has a child node and cannot add an adapter.
pub const ARKUI_ERROR_CODE_CHILD_NODE_EXIST: ArkUI_ErrorCode = ArkUI_ErrorCode(106106);
pub const CHILD_NODE_EXIST: ArkUiErrorCode =
ArkUiErrorCode(const { core::num::NonZero::new(106106).unwrap() });
}
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_ErrorCode {
impl ArkUiErrorCode {
/// The parameter length in the parameter event exceeds the limit.
pub const ARKUI_ERROR_CODE_NODE_EVENT_PARAM_INDEX_OUT_OF_RANGE: ArkUI_ErrorCode =
ArkUI_ErrorCode(106107);
pub const NODE_EVENT_PARAM_INDEX_OUT_OF_RANGE: ArkUiErrorCode =
ArkUiErrorCode(const { core::num::NonZero::new(106107).unwrap() });
}
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_ErrorCode {
impl ArkUiErrorCode {
/// The data does not exist in the component event.
pub const ARKUI_ERROR_CODE_NODE_EVENT_PARAM_INVALID: ArkUI_ErrorCode = ArkUI_ErrorCode(106108);
pub const NODE_EVENT_PARAM_INVALID: ArkUiErrorCode =
ArkUiErrorCode(const { core::num::NonZero::new(106108).unwrap() });
}
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_ErrorCode {
impl ArkUiErrorCode {
/// The component event does not support return values.
pub const ARKUI_ERROR_CODE_NODE_EVENT_NO_RETURN: ArkUI_ErrorCode = ArkUI_ErrorCode(106109);
pub const NODE_EVENT_NO_RETURN: ArkUiErrorCode =
ArkUiErrorCode(const { core::num::NonZero::new(106109).unwrap() });
}
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_ErrorCode {
impl ArkUiErrorCode {
/// The index value is invalid.
pub const ARKUI_ERROR_CODE_NODE_INDEX_INVALID: ArkUI_ErrorCode = ArkUI_ErrorCode(106200);
pub const NODE_INDEX_INVALID: ArkUiErrorCode =
ArkUiErrorCode(const { core::num::NonZero::new(106200).unwrap() });
}
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_ErrorCode {
impl ArkUiErrorCode {
/// Failed to query route navigation information.
pub const ARKUI_ERROR_CODE_GET_INFO_FAILED: ArkUI_ErrorCode = ArkUI_ErrorCode(106201);
pub const GET_INFO_FAILED: ArkUiErrorCode =
ArkUiErrorCode(const { core::num::NonZero::new(106201).unwrap() });
}
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_ErrorCode {
impl ArkUiErrorCode {
/// The buffer size is not large enough.
pub const ARKUI_ERROR_CODE_BUFFER_SIZE_ERROR: ArkUI_ErrorCode = ArkUI_ErrorCode(106202);
pub const BUFFER_SIZE_ERROR: ArkUiErrorCode =
ArkUiErrorCode(const { core::num::NonZero::new(106202).unwrap() });
}
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_ErrorCode {
impl ArkUiErrorCode {
/// The component is not a scroll container.
pub const ARKUI_ERROR_CODE_NON_SCROLLABLE_CONTAINER: ArkUI_ErrorCode = ArkUI_ErrorCode(180001);
pub const NON_SCROLLABLE_CONTAINER: ArkUiErrorCode =
ArkUiErrorCode(const { core::num::NonZero::new(180001).unwrap() });
}
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_ErrorCode {
impl ArkUiErrorCode {
/// The buffer is not large enough.
pub const ARKUI_ERROR_CODE_BUFFER_SIZE_NOT_ENOUGH: ArkUI_ErrorCode = ArkUI_ErrorCode(180002);
pub const BUFFER_SIZE_NOT_ENOUGH: ArkUiErrorCode =
ArkUiErrorCode(const { core::num::NonZero::new(180002).unwrap() });
}
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_ErrorCode {
impl ArkUiErrorCode {
/// invalid styled string.
///
/// Available since API-level: 14
#[cfg(feature = "api-14")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-14")))]
pub const ARKUI_ERROR_CODE_INVALID_STYLED_STRING: ArkUI_ErrorCode = ArkUI_ErrorCode(180101);
pub const INVALID_STYLED_STRING: ArkUiErrorCode =
ArkUiErrorCode(const { core::num::NonZero::new(180101).unwrap() });
}
pub type ArkUiResult = Result<(), ArkUiErrorCode>;
#[repr(transparent)]
/// Define error code enumeration values.
///
Expand All @@ -3716,7 +3724,7 @@ impl ArkUI_ErrorCode {
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
#[derive(Copy, Clone, Hash, PartialEq, Eq)]
pub struct ArkUI_ErrorCode(pub ::core::ffi::c_uint);
pub struct ArkUiErrorCode(pub core::num::NonZero<::core::ffi::c_uint>);
#[cfg(feature = "api-12")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
impl ArkUI_AnimationStatus {
Expand Down
Loading

0 comments on commit d72b6ab

Please sign in to comment.