Skip to content

Commit a532072

Browse files
Rename Host::check_same_env to Host::is_same (#1555)
### What Rename the host comparison method from check_same_env to is_same, changing it to return a boolean instead of a Result. ### Why The new name better reflects the method's purpose of being used by the SDK to compare two Hosts and determine if they in fact are the same underlying host implementation. The check function returns a result with the host assuming that there is in fact an error, whilst the is function returns a bool, merely providing information to the SDK so that the SDK can then decide in the context of its use whether there is an error or a change in behaviour is required. Close #1554 Related: - stellar/rs-soroban-sdk#1467 (comment)
1 parent 28a3e19 commit a532072

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

soroban-env-host/src/host.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -744,17 +744,10 @@ impl Host {
744744
self.create_contract_internal(Some(deployer), args, constructor_args_vec)
745745
}
746746

747-
pub fn check_same_env(&self, other: &Self) -> Result<(), HostError> {
748-
if Rc::ptr_eq(&self.0, &other.0) {
749-
Ok(())
750-
} else {
751-
Err(self.err(
752-
ScErrorType::Context,
753-
ScErrorCode::InternalError,
754-
"check_same_env on different Hosts",
755-
&[],
756-
))
757-
}
747+
/// Returns true if the Host contains the same instance of HostImpl and therefore changes to
748+
/// one will be observable via the other. If true, both are essentially the same Host.
749+
pub fn is_same(&self, other: &Self) -> bool {
750+
Rc::ptr_eq(&self.0, &other.0)
758751
}
759752
}
760753

soroban-env-host/src/test/host.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ use crate::{
77
Env, Host, HostError,
88
};
99

10+
#[test]
11+
fn is_same_host_impl() {
12+
let host1 = Host::default();
13+
let host1_clone = host1.clone();
14+
let host2 = Host::default();
15+
16+
assert!(host1.is_same(&host1));
17+
assert!(host1.is_same(&host1_clone));
18+
assert!(!host1.is_same(&host2));
19+
}
20+
1021
#[test]
1122
fn invalid_object_handles() -> Result<(), HostError> {
1223
let create_host = || -> Result<Host, HostError> {

0 commit comments

Comments
 (0)