首页 > 其他分享 >Arc get_mut

Arc get_mut

时间:2023-06-01 10:57:30浏览次数:44  
标签:mut reference get clone Arc make

/// Returns a mutable reference into the given `Arc`, if there are
    /// no other `Arc` or [`Weak`] pointers to the same allocation.
    ///
    /// Returns [`None`] otherwise, because it is not safe to
    /// mutate a shared value.
    ///
    /// See also [`make_mut`][make_mut], which will [`clone`][clone]
    /// the inner value when there are other `Arc` pointers.
    ///
    /// [make_mut]: Arc::make_mut
    /// [clone]: Clone::clone
    ///
    /// # Examples
    ///
    /// ```
    /// use std::sync::Arc;
    ///
    /// let mut x = Arc::new(3);
    /// *Arc::get_mut(&mut x).unwrap() = 4;
    /// assert_eq!(*x, 4);
    ///
    /// let _y = Arc::clone(&x);
    /// assert!(Arc::get_mut(&mut x).is_none());
    /// ```
    #[inline]
    #[stable(feature = "arc_unique", since = "1.4.0")]
    pub fn get_mut(this: &mut Self) -> Option<&mut T> {
        if this.is_unique() {
            // This unsafety is ok because we're guaranteed that the pointer
            // returned is the *only* pointer that will ever be returned to T. Our
            // reference count is guaranteed to be 1 at this point, and we required
            // the Arc itself to be `mut`, so we're returning the only possible
            // reference to the inner data.
            unsafe { Some(Arc::get_mut_unchecked(this)) }
        } else {
            None
        }
    }

 

标签:mut,reference,get,clone,Arc,make
From: https://www.cnblogs.com/itfanr/p/17448288.html

相关文章

  • MyBatis+Sharding-JDBC实体类LocalDateTime类型字段查询报SQLFeatureNotSupportedExce
    问题最近协助渠道组开发新需求,封装实现了一个公共模块供不同渠道项目使用。以前各个渠道项目有很多相似的菜单和功能,各自项目里自己的代码实现,本公共模块对新需求的功能点进行抽象,减少重复代码,提高模块复用性和可维护性。目前有2个渠道项目接入了该公共模块,自测时发现其中1个运......
  • sklearn gridsearch不能使用验证集导致的过拟合问题
    https://stackoverflow.com/questions/31948879/using-explicit-predefined-validation-set-for-grid-search-with-sklearn  或者用optuna####useoptunalibtofinetuneSVChyperparametersifmethod=='optuna':importoptuna......
  • elasticsearch3
    模糊查询#前缀搜索:prefix概念:以xx开头的搜索,不计算相关度评分。注意:前缀搜索匹配的是term,而不是field。前缀搜索的性能很差前缀搜索没有缓存前缀搜索尽可能把前缀长度设置的更长语法:GET<index>/_search{"query":{"prefix":{"<fiel......
  • 系数矩阵为Hessian矩阵时的使用Pearlmutter trick的共轭梯度解法
    共轭梯度法已经在前文中给出介绍:python版本的“共轭梯度法”算法代码  =======================================  使用共轭梯度法时,如果系数矩阵为Hessian矩阵,那么我们可以使用Pearlmuttertrick技术来减少计算过程中的内存消耗,加速计算。 使用Pearlmuttertrick的......
  • 内核mutex实现机制
    mutexmutex是内核中的互斥锁实现,本文对内核中的mutex机制进行了学习,在此记录一下。mutex结构体和定义structmutex{atomic_long_towner;//mutex持有的taskspinlock_twait_lock;//wait-lock的spinlock#ifdefCONFIG_MUTEX_SPIN_ON_OWNERstruc......
  • next_permutation函数
    next_permutation的函数声明:#include <algorithm> boolnext_permutation(iteratorstart,iteratorend);next_permutation函数的返回值是布尔类型,在STL中还有perv_permutation()函数 #include<iostream>#include<algorithm>#include<string>usingnamespacest......
  • ARC161F Everywhere is Sparser than Whole (Judge)
    题面传送门先大概移个项,就是要你找有没有非空真导出子图满足\(E-ND\geq0\)。如果它只问了\(E-ND>0\)这是经典的最大权闭合子图模型,令每条边为左部点,每个点为右部点,边的权值为\(1\),点的权值为\(-D\),边与对应点连边,如果最终最大权\(>0\),则存在这么一个子图。但是\(E-ND=......
  • Elasticsearch专题精讲—— REST APIs —— Document APIs —— 索引API
    RESTAPIs——DocumentAPIs——索引APIhttps://www.elastic.co/guide/en/elasticsearch/reference/8.8/docs-index_.html#docs-index_ AddsaJSONdocumenttothespecifieddatastreamorindexandmakesitsearchable.Ifthetargetisanindexandth......
  • kibana智能检索发送多次_msearch —— 配置index pattern,同时设置时间段,就知道到底是
    kibanasite/elasticsearch/log-*/_field_stats?level=indices   返回:{"_shards":{"total":600,"successful":600,"failed":0},"indices":{"log-2017.11.22-19-192.168.2.3-93004":{"fields":{"Rec......
  • python 中 re.match和re.search()函数
     两者都返回首次匹配字符串的索引,re.match函数只从头开始匹配,re.search函数不限制只从头开始匹配。001、re.match函数[root@PC1test2]#python3Python3.10.9(main,Mar12023,18:23:06)[GCC11.2.0]onlinuxType"help","copyright","credits"or"license"......