rust


How safe is this behavior of GTK-rs Builder::get_object?


In The Rust Programming Language, it says something like:
Move semantics
There’s some more subtlety here, though: Rust ensures that there is
exactly one binding to any given resource. For example, if we have a
vector, we can assign it to another binding:
But I found that I can do this using gtk-rs:
let label1: gtk::Label = builder.get_object("label1").unwrap();
let label1_test: gtk::Label = builder.get_object("label1").unwrap();
Both now point to the same resource "or something happens to me."
Builder::get_object is defined as:
pub fn get_object<T: IsA<Object>>(&self, name: &str) -> Option<T> {
unsafe {
Option::<Object>::from_glib_none(
ffi::gtk_builder_get_object(self.to_glib_none().0, name.to_glib_none().0))
.and_then(|obj| obj.downcast().ok())
}
}
Although this is not really something from Rust directly, just from gtk-rs, I was wondering if I am right and how sure is this.
Maybe it could use Rc?

Related Links

Cannot use downcast Any to an array containing references
How to avoid excessive cloning in Rust?
Changing mutable reference in a loop [duplicate]
Align struct to cache lines in Rust
Method not compatible with trait with confusing error message
How is an argument delivered across closure and function?
Expected concrete lifetime, found bound lifetime parameter when storing a fn in a struct
Concise way to box an Option
Rust Match Struct Attribute in Method Fails Borrow Checker
Why would a function taking no arguments and returning a reference have a lifetime error? [duplicate]
Are there queue and stack collections?
Is there an idiomatic way to keep references to elements of an ever-growing container?
Why do “large” arrays not implement std::fmt::Debug? [duplicate]
Why isn't `use std::io` enough here?
How to make a simple futures::sync::mpsc::channel example work?
Is there a way to let Rust infer the correct type for an associated type?

Categories

HOME
d3.js
bots
redmine
kivy
initialization
flurry
openfoam
ag-grid
graphql-js
phpseclib
stack-overflow
google-awareness
texas-instruments
asciimath
android-contacts
string-formatting
renderscript
infrared
stackexchange.redis
dragula
opentext
window-managers
hevc
android-service
points
bobo-browse.net
ibm-connections
materialize
autodesk-model-derivative
sql-execution-plan
advanced-filter
payeezy
gnu-classpath
autoencoder
nppexec
nsuserdefaults
sbjson
resampling
newtons-method
klee
autorelease
libreoffice-writer
openstack-glance
node-apn
visual-format-language
extjs4.1
palindrome
pbx
yui3
msg
bbc-micro
simian
vaadin4spring
textblock
flask-security
odesk
miniconda
variable-length-array
self
ambiguity
extend
canopy
apple
blockquote
domino-designer-eclipse
textscan
phpredis
erlog
deque
text-align
fat32
vs-unit-testing-framework
dc
aho-corasick
git-reset
csslint
flipboard
meteorite
illuminate-container
grails-2.3
iirf
eager-loading
ui-design
proc-open
jsplitpane
audiotoolbox
popup-blocker
expression-web
litespeed
servercontrol
nsrangeexception
regression-testing
jdownloader
multiple-users
odac
spring-modules
word-automation

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App