Skip to content

Commit b9f2d97

Browse files
committed
feat(array): take i64 instead of u64 as index
1 parent 6e1789e commit b9f2d97

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/types/array.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ impl ZendHashTable {
279279
/// assert_eq!(ht.get_index(0).and_then(|zv| zv.long()), Some(100));
280280
/// ```
281281
#[must_use]
282-
pub fn get_index(&self, key: u64) -> Option<&Zval> {
283-
unsafe { zend_hash_index_find(self, key).as_ref() }
282+
pub fn get_index(&self, key: i64) -> Option<&Zval> {
283+
unsafe { zend_hash_index_find(self, key as zend_ulong).as_ref() }
284284
}
285285

286286
/// Attempts to retrieve a value from the hash table with an index.
@@ -306,8 +306,8 @@ impl ZendHashTable {
306306
/// assert_eq!(ht.get_index(0).and_then(|zv| zv.long()), Some(100));
307307
/// ```
308308
#[must_use]
309-
pub fn get_index_mut(&self, key: u64) -> Option<&mut Zval> {
310-
unsafe { zend_hash_index_find(self, key).as_mut() }
309+
pub fn get_index_mut(&self, key: i64) -> Option<&mut Zval> {
310+
unsafe { zend_hash_index_find(self, key as zend_ulong).as_mut() }
311311
}
312312

313313
/// Attempts to remove a value from the hash table with a string key.
@@ -386,8 +386,8 @@ impl ZendHashTable {
386386
/// ht.remove_index(0);
387387
/// assert_eq!(ht.len(), 0);
388388
/// ```
389-
pub fn remove_index(&mut self, key: u64) -> Option<()> {
390-
let result = unsafe { zend_hash_index_del(self, key) };
389+
pub fn remove_index(&mut self, key: i64) -> Option<()> {
390+
let result = unsafe { zend_hash_index_del(self, key as zend_ulong) };
391391

392392
if result < 0 {
393393
None
@@ -482,12 +482,12 @@ impl ZendHashTable {
482482
/// ht.insert_at_index(0, "C"); // notice overriding index 0
483483
/// assert_eq!(ht.len(), 2);
484484
/// ```
485-
pub fn insert_at_index<V>(&mut self, key: u64, val: V) -> Result<()>
485+
pub fn insert_at_index<V>(&mut self, key: i64, val: V) -> Result<()>
486486
where
487487
V: IntoZval,
488488
{
489489
let mut val = val.into_zval(false)?;
490-
unsafe { zend_hash_index_update(self, key, &mut val) };
490+
unsafe { zend_hash_index_update(self, key as zend_ulong, &mut val) };
491491
val.release();
492492
Ok(())
493493
}
@@ -1135,8 +1135,8 @@ impl FromIterator<Zval> for ZBox<ZendHashTable> {
11351135
}
11361136
}
11371137

1138-
impl FromIterator<(u64, Zval)> for ZBox<ZendHashTable> {
1139-
fn from_iter<T: IntoIterator<Item = (u64, Zval)>>(iter: T) -> Self {
1138+
impl FromIterator<(i64, Zval)> for ZBox<ZendHashTable> {
1139+
fn from_iter<T: IntoIterator<Item = (i64, Zval)>>(iter: T) -> Self {
11401140
let mut ht = ZendHashTable::new();
11411141
for (key, val) in iter {
11421142
// Inserting a zval cannot fail, as `push` only returns `Err` if converting

0 commit comments

Comments
 (0)