Comprehensive Rust Ch.16.2 – pattern matching for structs using capture and const expressions

Advertisements Having trouble understanding the second speaker note point in the Pattern Matching – Destructuring structs of the Comprehensive Rust by Google. Here is the sample code. struct Foo { x: (u32, u32), y: u32, } #[rustfmt::skip] fn main() { let foo = Foo { x: (1, 2), y: 3 }; match foo { Foo… Read More Comprehensive Rust Ch.16.2 – pattern matching for structs using capture and const expressions

Replace All numeric substring with character

Advertisements I have to replace all digit patterns with some character. For 1 digit its working fine for e.g for given string ramesh_gone_to_avbp_9_vc.pdf its working fine changing it to ramesh_gone_to_avbp_*_vc.pdf but for given input ramesh_gone_to_avbp_91_vc.pdf its changing to ramesh_gone_to_avbp_**_vc.pdf but i want output like ramesh_gone_to_avbp_*_vc.pdf This is what i tried so far String ss =… Read More Replace All numeric substring with character

How to handle to read a column and cast to Option[String] from postgre db which has null and string values in Scala 2?

Advertisements I had a problem with null data coming from one of the postgre db tables. In my situation, I have a column that is nullable which means it stores originally varchar data but has also null values for some rows. I read that column as Any data type inside Scala 2. My first problem… Read More How to handle to read a column and cast to Option[String] from postgre db which has null and string values in Scala 2?

How to identify a repetitive type of patter with regex (c#)

Advertisements Currently I’m doing: Regex.Match(ln, "\"[\\u0000-\\u007E]+\"") The problem is if ln is like ""text…"" it won’t work as wanted. Same to """text…""", etc… How can i make the " " repetitive? It should also match to "text1"text2"text3". The point is, it should match with the most 2 outer " " if the number of "… Read More How to identify a repetitive type of patter with regex (c#)

Is `if let` just another way of writing other `if` statements?

Advertisements So I’m learning Rust and I’m learning about pattern matching and "if let" statements as alternatives to matching expressions. I was watching this video regarding "if let" which is mentioned at 11:00 and they give this example: fn main() { let some_value: Option<i32> = Some(3); if let Some(3) = some_value { println!("three"); } }… Read More Is `if let` just another way of writing other `if` statements?

inconsistent non-exhaustive pattern matching with if statements

Advertisements I’ve wrote two equivalent functions in Rust, one compiles the other doesn’t. Program 1: pub fn majority_element<T: Eq>(nums: &[T]) -> Option<&T> { nums.iter().fold(None, |acc, curr| { match acc { None => Some((1, curr)), Some((0, prev)) if prev != curr => Some((1, curr)), Some((count, prev)) => Some((count + if prev == curr { 1 }… Read More inconsistent non-exhaustive pattern matching with if statements