pub struct Candidate { /* private fields */ }Expand description
One option to balance between, described by a bag of named values (its state): a hostname, whether it is online, its load.
Keys follow PHP array rules: a decimal key such as "0" is stored as the
integer 0, so Candidate::states is the array PHP would hold.
PHP: Utopia\Balancer\Option.
use php_std::Value;
use utopia_balancer::Candidate;
let mut worker = Candidate::default();
worker.set("hostname", Value::from("worker-1")).set("cpu", Value::from(35));
assert_eq!(worker.get("cpu"), Some(&Value::Int(35)));
assert_eq!(worker.get_or("memory", &Value::Int(0)), &Value::Int(0));
assert_eq!(worker.states().len(), 2);use Utopia\Balancer\Option;
$worker = new Option([]);
$worker->setState('hostname', 'worker-1')->setState('cpu', 35);
var_dump($worker->getState('cpu')); // int(35)
var_dump($worker->getState('memory', 0)); // int(0)
var_dump(\count($worker->getStates())); // int(2)Implementations§
Source§impl Candidate
impl Candidate
Sourcepub fn get(&self, key: &str) -> Option<&Value>
pub fn get(&self, key: &str) -> Option<&Value>
The value of key, or None when it is missing or null.
PHP: getState($key), which returns null for both.
Sourcepub fn get_or<'a>(&'a self, key: &str, default: &'a Value) -> &'a Value
pub fn get_or<'a>(&'a self, key: &str, default: &'a Value) -> &'a Value
The value of key, or default when it is missing or null.
PHP: getState($key, $default) ($state[$key] ?? $default).
Sourcepub fn set(&mut self, key: &str, value: Value) -> &mut Self
pub fn set(&mut self, key: &str, value: Value) -> &mut Self
Sets key to value, replacing any previous value in place.
PHP: setState($key, $value).
Trait Implementations§
impl StructuralPartialEq for Candidate
Auto Trait Implementations§
impl Forget for Candidate
impl Freeze for Candidate
impl Move for Candidate
impl RefUnwindSafe for Candidate
impl Send for Candidate
impl Sync for Candidate
impl Unpin for Candidate
impl UnsafeUnpin for Candidate
impl UnwindSafe for Candidate
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more