The answers to all your questions is a loud "No!".
Embedding a
string
into a struct is basically a useless example of embedding asstring
has no methods which could get promoted to the embedding type.The construct
type Txt string
defines a new type named Txt and the underlying type is a string.Txt
has different method set as it is a different type. But as its underlying type isstring
you may freely type convert them.type T string
is not a shortcut fortype S struct { string }
, e.g. you cannot dot := T{"foo"}
, onlyt := T("foo")
works and forS
it is the other way around.Embedding has absolutely no relation to inheritance. These are two different things. Mimicking inheritance with embedding is doomed to fail as you cannot do inheritance in Go. (This is a general advice, it is a very useful advice; but some specific inheritance problems might be doable with embedding. Just forget about inheritance and you will be happier.)
Embedding is useful if two types have common data and methods in which case embedding provides some nice syntactic sugar: Instead of
type T struct { c common; r rest }; t := T{...}; t.common.method()
you can dotype T struct { common; r rest }; t := T{...}; t.method()
which saves typing but is basically the same code. Package testing contains nice examples.