पर विचार करें निम्न उदाहरणत्रुटि मिलान
fn main() {
f("hello", true);
}
fn f(str: &str, sen: bool) {
let s: &str = match sen {
false => str,
true => str.chars().map(|x| x.to_lowercase()).collect().as_slice()
};
println!("{}", s);
}
मैं यह त्रुटि
error: the type of this value must be known in this conntext
true => str.chars().map(|x| x.to_lowercase()).collect().as_slice()
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
मैं थोड़ा उलझन में हूँ हो रही है पैटर्न में "इस मान का प्रकार इस संदर्भ में पता होना चाहिए", संकलक को पता नहीं है कि str
का प्रकार &str
फ़ंक्शन परिभाषा से है? मुझे यहां क्या समझ नहीं आ रहा है?
धन्यवाद। मैं 'स्ट्रिंग' को स्टोर करने के लिए अस्थायी चर का उपयोग कर समाप्त हुआ और एस को बाध्य करता हूं 'temp_var.as_slice() '। सुनिश्चित नहीं है कि हालांकि एक बेहतर तरीका है या नहीं। –