ResultBox migration complete: remove legacy box_trait::ResultBox
- Delete deprecated ResultBox implementation from box_trait.rs - All code paths use boxes::result::NyashResultBox (aka boxes::ResultBox) - Tests remain green (179) - Mark phase 9.78h acceptance: ResultBox移行完了 as done
This commit is contained in:
153
src/box_trait.rs
153
src/box_trait.rs
@ -719,159 +719,6 @@ impl Display for ErrorBox {
|
||||
}
|
||||
}
|
||||
|
||||
/// Result values in Nyash - represents success or error results
|
||||
#[deprecated(note = "Use boxes::result::NyashResultBox (aka boxes::ResultBox) instead")]
|
||||
#[derive(Debug)]
|
||||
pub struct ResultBox {
|
||||
pub is_success: bool,
|
||||
pub value: Option<Box<dyn NyashBox>>,
|
||||
pub error: Option<ErrorBox>,
|
||||
base: BoxBase,
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl ResultBox {
|
||||
pub fn new_success(value: Box<dyn NyashBox>) -> Self {
|
||||
Self {
|
||||
is_success: true,
|
||||
value: Some(value),
|
||||
error: None,
|
||||
base: BoxBase::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_error(error: ErrorBox) -> Self {
|
||||
Self {
|
||||
is_success: false,
|
||||
value: None,
|
||||
error: Some(error),
|
||||
base: BoxBase::new(),
|
||||
}
|
||||
}
|
||||
|
||||
// ===== Result Methods for Nyash =====
|
||||
|
||||
/// Check if result is successful
|
||||
pub fn is_ok(&self) -> Box<dyn NyashBox> {
|
||||
Box::new(BoolBox::new(self.is_success))
|
||||
}
|
||||
|
||||
/// Get success value (returns void if error)
|
||||
pub fn get_value(&self) -> Box<dyn NyashBox> {
|
||||
match &self.value {
|
||||
Some(val) => val.clone_box(),
|
||||
None => Box::new(VoidBox::new()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get error (returns void if success)
|
||||
pub fn get_error(&self) -> Box<dyn NyashBox> {
|
||||
match &self.error {
|
||||
Some(err) => Box::new(err.clone()),
|
||||
None => Box::new(VoidBox::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl BoxCore for ResultBox {
|
||||
fn box_id(&self) -> u64 {
|
||||
self.base.id
|
||||
}
|
||||
|
||||
fn parent_type_id(&self) -> Option<std::any::TypeId> {
|
||||
self.base.parent_type_id
|
||||
}
|
||||
|
||||
fn fmt_box(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, "{}", self.to_string_box().value)
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl NyashBox for ResultBox {
|
||||
fn to_string_box(&self) -> StringBox {
|
||||
if self.is_success {
|
||||
if let Some(value) = &self.value {
|
||||
StringBox::new(format!("Result(OK: {})", value.to_string_box().value))
|
||||
} else {
|
||||
StringBox::new("Result(OK: void)".to_string())
|
||||
}
|
||||
} else {
|
||||
if let Some(error) = &self.error {
|
||||
StringBox::new(format!("Result(Error: {})", error.to_string_box().value))
|
||||
} else {
|
||||
StringBox::new("Result(Error: unknown)".to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn equals(&self, other: &dyn NyashBox) -> BoolBox {
|
||||
if let Some(other_result) = other.as_any().downcast_ref::<ResultBox>() {
|
||||
if self.is_success != other_result.is_success {
|
||||
return BoolBox::new(false);
|
||||
}
|
||||
|
||||
if self.is_success {
|
||||
// Compare success values
|
||||
match (&self.value, &other_result.value) {
|
||||
(Some(a), Some(b)) => a.equals(b.as_ref()),
|
||||
(None, None) => BoolBox::new(true),
|
||||
_ => BoolBox::new(false),
|
||||
}
|
||||
} else {
|
||||
// Compare errors
|
||||
match (&self.error, &other_result.error) {
|
||||
(Some(a), Some(b)) => a.equals(b),
|
||||
(None, None) => BoolBox::new(true),
|
||||
_ => BoolBox::new(false),
|
||||
}
|
||||
}
|
||||
} else {
|
||||
BoolBox::new(false)
|
||||
}
|
||||
}
|
||||
|
||||
fn type_name(&self) -> &'static str {
|
||||
"ResultBox"
|
||||
}
|
||||
|
||||
fn clone_box(&self) -> Box<dyn NyashBox> {
|
||||
if self.is_success {
|
||||
if let Some(value) = &self.value {
|
||||
Box::new(ResultBox::new_success(value.clone_box()))
|
||||
} else {
|
||||
Box::new(ResultBox::new_success(Box::new(VoidBox::new())))
|
||||
}
|
||||
} else {
|
||||
if let Some(error) = &self.error {
|
||||
Box::new(ResultBox::new_error(error.clone()))
|
||||
} else {
|
||||
Box::new(ResultBox::new_error(ErrorBox::new("Unknown", "Unknown error")))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 仮実装: clone_boxと同じ(後で修正)
|
||||
fn share_box(&self) -> Box<dyn NyashBox> {
|
||||
self.clone_box()
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl Display for ResultBox {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
self.fmt_box(f)
|
||||
}
|
||||
}
|
||||
|
||||
// FutureBox is now implemented in src/boxes/future/mod.rs using RwLock pattern
|
||||
// and re-exported from src/boxes/mod.rs as both NyashFutureBox and FutureBox
|
||||
|
||||
Reference in New Issue
Block a user